<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - optimization_bobyqa.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2009 M.J.D. Powell, Davis E. King (davis@dlib.net)
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font><font color='#0000FF'>#ifndef</font> DLIB_OPTIMIZATIOn_BOBYQA_Hh_
<font color='#0000FF'>#define</font> DLIB_OPTIMIZATIOn_BOBYQA_Hh_

<font color='#009900'>/*
    The code in this file is derived from Powell's BOBYQA Fortran code.
    It was created by running f2c on the original Fortran code and then 
    massaging the resulting C code into what you can see below.


    The following paper, published in 2009 by Powell, describes the
    detailed workings of the BOBYQA algorithm.  

        The BOBYQA algorithm for bound constrained optimization 
        without derivatives by M.J.D. Powell
*/</font>

<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>algorithm<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>cmath<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../matrix.h.html'>../matrix.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../smart_pointers.h.html'>../smart_pointers.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='optimization_bobyqa_abstract.h.html'>optimization_bobyqa_abstract.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='optimization.h.html'>optimization.h</a>"

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>namespace</font> dlib
<b>{</b>

    <font color='#0000FF'>class</font> <b><a name='bobyqa_failure'></a>bobyqa_failure</b> : <font color='#0000FF'>public</font> error <b>{</b>
    <font color='#0000FF'>public</font>: <b><a name='bobyqa_failure'></a>bobyqa_failure</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> s<font face='Lucida Console'>)</font>:error<font face='Lucida Console'>(</font>s<font face='Lucida Console'>)</font><b>{</b><b>}</b>
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='bobyqa_implementation'></a>bobyqa_implementation</b>
    <b>{</b>
        <font color='#0000FF'>typedef</font> <font color='#0000FF'><u>long</u></font> integer;
        <font color='#0000FF'>typedef</font> <font color='#0000FF'><u>double</u></font> doublereal;

    <font color='#0000FF'>public</font>:

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> funct,
            <font color='#0000FF'>typename</font> T, 
            <font color='#0000FF'>typename</font> U
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>double</u></font> <b><a name='find_min'></a>find_min</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> funct<font color='#5555FF'>&amp;</font> f,
            T<font color='#5555FF'>&amp;</font> x,
            <font color='#0000FF'><u>long</u></font> npt,
            <font color='#0000FF'>const</font> U<font color='#5555FF'>&amp;</font> xl_,
            <font color='#0000FF'>const</font> U<font color='#5555FF'>&amp;</font> xu_,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> rhobeg,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> rhoend,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> max_f_evals
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> n <font color='#5555FF'>=</font> x.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> w_size <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>npt<font color='#5555FF'>+</font><font color='#979000'>5</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font>npt<font color='#5555FF'>+</font>n<font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>3</font><font color='#5555FF'>*</font>n<font color='#5555FF'>*</font><font face='Lucida Console'>(</font>n<font color='#5555FF'>+</font><font color='#979000'>5</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>;
            scoped_ptr<font color='#5555FF'>&lt;</font>doublereal[]<font color='#5555FF'>&gt;</font> <font color='#BB00BB'>w</font><font face='Lucida Console'>(</font><font color='#0000FF'>new</font> doublereal[w_size]<font face='Lucida Console'>)</font>;

            <font color='#009900'>// make these temporary matrices becuse U might be some
</font>            <font color='#009900'>// kind of matrix_exp that doesn't support taking the address
</font>            <font color='#009900'>// of the first element.
</font>            matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>xl</font><font face='Lucida Console'>(</font>xl_<font face='Lucida Console'>)</font>;
            matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>xu</font><font face='Lucida Console'>(</font>xu_<font face='Lucida Console'>)</font>;

            
            <font color='#0000FF'>return</font> <font color='#BB00BB'>bobyqa_</font> <font face='Lucida Console'>(</font>f,
                            x.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                            npt,
                            <font color='#5555FF'>&amp;</font><font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,
                            <font color='#5555FF'>&amp;</font><font color='#BB00BB'>xl</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,
                            <font color='#5555FF'>&amp;</font><font color='#BB00BB'>xu</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,
                            rhobeg,
                            rhoend,
                            max_f_evals,
                            w.<font color='#BB00BB'>get</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>;
        <b>}</b>

    <font color='#0000FF'>private</font>:


        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> funct<font color='#5555FF'>&gt;</font>
        doublereal <b><a name='bobyqa_'></a>bobyqa_</b><font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> funct<font color='#5555FF'>&amp;</font> calfun,
            <font color='#0000FF'>const</font> integer n, 
            <font color='#0000FF'>const</font> integer npt, 
            doublereal <font color='#5555FF'>*</font>x, 
            <font color='#0000FF'>const</font> doublereal <font color='#5555FF'>*</font>xl,
            <font color='#0000FF'>const</font> doublereal <font color='#5555FF'>*</font>xu,
            <font color='#0000FF'>const</font> doublereal rhobeg,
            <font color='#0000FF'>const</font> doublereal rhoend,
            <font color='#0000FF'>const</font> integer maxfun,
            doublereal <font color='#5555FF'>*</font>w
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>

            <font color='#009900'>/* System generated locals */</font>
            integer i__1;
            doublereal d__1, d__2;

            <font color='#009900'>/* Local variables */</font>
            integer j, id_, np, iw, igo, ihq, ixb, ixa, ifv, isl, jsl, ipq, ivl, ixn, ixo, ixp, isu, jsu, ndim;
            doublereal temp, zero;
            integer ibmat, izmat;


            <font color='#009900'>/*     This subroutine seeks the least value of a function of many variables, */</font>
            <font color='#009900'>/*     by applying a trust region method that forms quadratic models by */</font>
            <font color='#009900'>/*     interpolation. There is usually some freedom in the interpolation */</font>
            <font color='#009900'>/*     conditions, which is taken up by minimizing the Frobenius norm of */</font>
            <font color='#009900'>/*     the change to the second derivative of the model, beginning with the */</font>
            <font color='#009900'>/*     zero matrix. The values of the variables are constrained by upper and */</font>
            <font color='#009900'>/*     lower bounds. The arguments of the subroutine are as follows. */</font>

            <font color='#009900'>/*     N must be set to the number of variables and must be at least two. */</font>
            <font color='#009900'>/*     NPT is the number of interpolation conditions. Its value must be in */</font>
            <font color='#009900'>/*       the interval [N+2,(N+1)(N+2)/2]. Choices that exceed 2*N+1 are not */</font>
            <font color='#009900'>/*       recommended. */</font>
            <font color='#009900'>/*     Initial values of the variables must be set in X(1),X(2),...,X(N). They */</font>
            <font color='#009900'>/*       will be changed to the values that give the least calculated F. */</font>
            <font color='#009900'>/*     For I=1,2,...,N, XL(I) and XU(I) must provide the lower and upper */</font>
            <font color='#009900'>/*       bounds, respectively, on X(I). The construction of quadratic models */</font>
            <font color='#009900'>/*       requires XL(I) to be strictly less than XU(I) for each I. Further, */</font>
            <font color='#009900'>/*       the contribution to a model from changes to the I-th variable is */</font>
            <font color='#009900'>/*       damaged severely by rounding errors if XU(I)-XL(I) is too small. */</font>
            <font color='#009900'>/*     RHOBEG and RHOEND must be set to the initial and final values of a trust */</font>
            <font color='#009900'>/*       region radius, so both must be positive with RHOEND no greater than */</font>
            <font color='#009900'>/*       RHOBEG. Typically, RHOBEG should be about one tenth of the greatest */</font>
            <font color='#009900'>/*       expected change to a variable, while RHOEND should indicate the */</font>
            <font color='#009900'>/*       accuracy that is required in the final values of the variables. An */</font>
            <font color='#009900'>/*       error return occurs if any of the differences XU(I)-XL(I), I=1,...,N, */</font>
            <font color='#009900'>/*       is less than 2*RHOBEG. */</font>
            <font color='#009900'>/*     MAXFUN must be set to an upper bound on the number of calls of CALFUN. */</font>
            <font color='#009900'>/*     The array W will be used for working space. Its length must be at least */</font>
            <font color='#009900'>/*       (NPT+5)*(NPT+N)+3*N*(N+5)/2. */</font>

            <font color='#009900'>/* Parameter adjustments */</font>
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>w;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>xu;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>xl;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>x;

            <font color='#009900'>/* Function Body */</font>
            np <font color='#5555FF'>=</font> n <font color='#5555FF'>+</font> <font color='#979000'>1</font>;

            <font color='#009900'>/*     Return if the value of NPT is unacceptable. */</font>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>npt <font color='#5555FF'>&lt;</font> n <font color='#5555FF'>+</font> <font color='#979000'>2</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> npt <font color='#5555FF'>&gt;</font> <font face='Lucida Console'>(</font>n <font color='#5555FF'>+</font> <font color='#979000'>2</font><font face='Lucida Console'>)</font> <font color='#5555FF'>*</font> np <font color='#5555FF'>/</font> <font color='#979000'>2</font><font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>throw</font> <font color='#BB00BB'>bobyqa_failure</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Return from BOBYQA because NPT is not in the required interval</font>"<font face='Lucida Console'>)</font>;
                <font color='#009900'>//goto L40;
</font>            <b>}</b>

            <font color='#009900'>/*     Partition the working space array, so that different parts of it can */</font>
            <font color='#009900'>/*     be treated separately during the calculation of BOBYQB. The partition */</font>
            <font color='#009900'>/*     requires the first (NPT+2)*(NPT+N)+3*N*(N+5)/2 elements of W plus the */</font>
            <font color='#009900'>/*     space that is taken by the last array in the argument list of BOBYQB. */</font>

            ndim <font color='#5555FF'>=</font> npt <font color='#5555FF'>+</font> n;
            ixb <font color='#5555FF'>=</font> <font color='#979000'>1</font>;
            ixp <font color='#5555FF'>=</font> ixb <font color='#5555FF'>+</font> n;
            ifv <font color='#5555FF'>=</font> ixp <font color='#5555FF'>+</font> n <font color='#5555FF'>*</font> npt;
            ixo <font color='#5555FF'>=</font> ifv <font color='#5555FF'>+</font> npt;
            igo <font color='#5555FF'>=</font> ixo <font color='#5555FF'>+</font> n;
            ihq <font color='#5555FF'>=</font> igo <font color='#5555FF'>+</font> n;
            ipq <font color='#5555FF'>=</font> ihq <font color='#5555FF'>+</font> n <font color='#5555FF'>*</font> np <font color='#5555FF'>/</font> <font color='#979000'>2</font>;
            ibmat <font color='#5555FF'>=</font> ipq <font color='#5555FF'>+</font> npt;
            izmat <font color='#5555FF'>=</font> ibmat <font color='#5555FF'>+</font> ndim <font color='#5555FF'>*</font> n;
            isl <font color='#5555FF'>=</font> izmat <font color='#5555FF'>+</font> npt <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>npt <font color='#5555FF'>-</font> np<font face='Lucida Console'>)</font>;
            isu <font color='#5555FF'>=</font> isl <font color='#5555FF'>+</font> n;
            ixn <font color='#5555FF'>=</font> isu <font color='#5555FF'>+</font> n;
            ixa <font color='#5555FF'>=</font> ixn <font color='#5555FF'>+</font> n;
            id_ <font color='#5555FF'>=</font> ixa <font color='#5555FF'>+</font> n;
            ivl <font color='#5555FF'>=</font> id_ <font color='#5555FF'>+</font> n;
            iw <font color='#5555FF'>=</font> ivl <font color='#5555FF'>+</font> ndim;

            <font color='#009900'>/*     Return if there is insufficient space between the bounds. Modify the */</font>
            <font color='#009900'>/*     initial X if necessary in order to avoid conflicts between the bounds */</font>
            <font color='#009900'>/*     and the construction of the first quadratic model. The lower and upper */</font>
            <font color='#009900'>/*     bounds on moves from the updated X are set now, in the ISL and ISU */</font>
            <font color='#009900'>/*     partitions of W, in order to provide useful and exact information about */</font>
            <font color='#009900'>/*     components of X that become within distance RHOBEG from their bounds. */</font>

            zero <font color='#5555FF'>=</font> <font color='#979000'>0.</font>;
            i__1 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                temp <font color='#5555FF'>=</font> xu[j] <font color='#5555FF'>-</font> xl[j];
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp <font color='#5555FF'>&lt;</font> rhobeg <font color='#5555FF'>+</font> rhobeg<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#0000FF'>throw</font> <font color='#BB00BB'>bobyqa_failure</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Return from BOBYQA because one of the differences in x_lower and x_upper is less than 2*rho_begin</font>"<font face='Lucida Console'>)</font>;
                    <font color='#009900'>//goto L40;
</font>                <b>}</b>
                jsl <font color='#5555FF'>=</font> isl <font color='#5555FF'>+</font> j <font color='#5555FF'>-</font> <font color='#979000'>1</font>;
                jsu <font color='#5555FF'>=</font> jsl <font color='#5555FF'>+</font> n;
                w[jsl] <font color='#5555FF'>=</font> xl[j] <font color='#5555FF'>-</font> x[j];
                w[jsu] <font color='#5555FF'>=</font> xu[j] <font color='#5555FF'>-</font> x[j];
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>w[jsl] <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font face='Lucida Console'>(</font>rhobeg<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>w[jsl] <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                        x[j] <font color='#5555FF'>=</font> xl[j];
                        w[jsl] <font color='#5555FF'>=</font> zero;
                        w[jsu] <font color='#5555FF'>=</font> temp;
                    <b>}</b> <font color='#0000FF'>else</font> <b>{</b>
                        x[j] <font color='#5555FF'>=</font> xl[j] <font color='#5555FF'>+</font> rhobeg;
                        w[jsl] <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font face='Lucida Console'>(</font>rhobeg<font face='Lucida Console'>)</font>;
                        <font color='#009900'>/* Computing MAX */</font>
                        d__1 <font color='#5555FF'>=</font> xu[j] <font color='#5555FF'>-</font> x[j];
                        w[jsu] <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__1,rhobeg<font face='Lucida Console'>)</font>;
                    <b>}</b>
                <b>}</b> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>w[jsu] <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> rhobeg<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>w[jsu] <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                        x[j] <font color='#5555FF'>=</font> xu[j];
                        w[jsl] <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>temp;
                        w[jsu] <font color='#5555FF'>=</font> zero;
                    <b>}</b> <font color='#0000FF'>else</font> <b>{</b>
                        x[j] <font color='#5555FF'>=</font> xu[j] <font color='#5555FF'>-</font> rhobeg;
                        <font color='#009900'>/* Computing MIN */</font>
                        d__1 <font color='#5555FF'>=</font> xl[j] <font color='#5555FF'>-</font> x[j], d__2 <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font face='Lucida Console'>(</font>rhobeg<font face='Lucida Console'>)</font>;
                        w[jsl] <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
                        w[jsu] <font color='#5555FF'>=</font> rhobeg;
                    <b>}</b>
                <b>}</b>
                <font color='#009900'>/* L30: */</font>
            <b>}</b>

            <font color='#009900'>/*     Make the call of BOBYQB. */</font>

            <font color='#0000FF'>return</font> <font color='#BB00BB'>bobyqb_</font><font face='Lucida Console'>(</font>calfun, n, npt, <font color='#5555FF'>&amp;</font>x[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>xl[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>xu[<font color='#979000'>1</font>], rhobeg, rhoend, maxfun, <font color='#5555FF'>&amp;</font>w[
                    ixb], <font color='#5555FF'>&amp;</font>w[ixp], <font color='#5555FF'>&amp;</font>w[ifv], <font color='#5555FF'>&amp;</font>w[ixo], <font color='#5555FF'>&amp;</font>w[igo], <font color='#5555FF'>&amp;</font>w[ihq], <font color='#5555FF'>&amp;</font>w[ipq], <font color='#5555FF'>&amp;</font>w[
                    ibmat], <font color='#5555FF'>&amp;</font>w[izmat], ndim, <font color='#5555FF'>&amp;</font>w[isl], <font color='#5555FF'>&amp;</font>w[isu], <font color='#5555FF'>&amp;</font>w[ixn], <font color='#5555FF'>&amp;</font>w[ixa], <font color='#5555FF'>&amp;</font>w[
                    id_], <font color='#5555FF'>&amp;</font>w[ivl], <font color='#5555FF'>&amp;</font>w[iw]<font face='Lucida Console'>)</font>;
            <font color='#009900'>//L40:
</font>            ;
        <b>}</b> <font color='#009900'>/* bobyqa_ */</font>

    <font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> funct<font color='#5555FF'>&gt;</font>
        doublereal <b><a name='bobyqb_'></a>bobyqb_</b><font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> funct<font color='#5555FF'>&amp;</font> calfun,
            <font color='#0000FF'>const</font> integer n,
            <font color='#0000FF'>const</font> integer npt,
            doublereal <font color='#5555FF'>*</font>x,
            <font color='#0000FF'>const</font> doublereal <font color='#5555FF'>*</font>xl,
            <font color='#0000FF'>const</font> doublereal <font color='#5555FF'>*</font>xu,
            <font color='#0000FF'>const</font> doublereal rhobeg,
            <font color='#0000FF'>const</font> doublereal rhoend,
            <font color='#0000FF'>const</font> integer maxfun,
            doublereal <font color='#5555FF'>*</font>xbase, 
            doublereal <font color='#5555FF'>*</font>xpt,
            doublereal <font color='#5555FF'>*</font>fval,
            doublereal <font color='#5555FF'>*</font>xopt,
            doublereal <font color='#5555FF'>*</font>gopt,
            doublereal <font color='#5555FF'>*</font>hq,
            doublereal <font color='#5555FF'>*</font>pq,
            doublereal <font color='#5555FF'>*</font>bmat,
            doublereal <font color='#5555FF'>*</font>zmat, 
            <font color='#0000FF'>const</font> integer ndim,
            doublereal <font color='#5555FF'>*</font>sl,
            doublereal <font color='#5555FF'>*</font>su, 
            doublereal <font color='#5555FF'>*</font>xnew, 
            doublereal <font color='#5555FF'>*</font>xalt,
            doublereal <font color='#5555FF'>*</font>d__,
            doublereal <font color='#5555FF'>*</font>vlag, 
            doublereal <font color='#5555FF'>*</font>w
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            <font color='#009900'>/* System generated locals */</font>
            integer xpt_dim1, xpt_offset, bmat_dim1, bmat_offset, zmat_dim1, 
            zmat_offset, i__1, i__2, i__3;
            doublereal d__1, d__2, d__3, d__4;

            <font color='#009900'>/* Local variables */</font>
            doublereal f <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            integer i__, j, k, ih, nf, jj, nh, ip, jp;
            doublereal dx;
            integer np;
            doublereal den <font color='#5555FF'>=</font> <font color='#979000'>0</font>, one <font color='#5555FF'>=</font> <font color='#979000'>0</font>, ten <font color='#5555FF'>=</font> <font color='#979000'>0</font>, dsq <font color='#5555FF'>=</font> <font color='#979000'>0</font>, rho <font color='#5555FF'>=</font> <font color='#979000'>0</font>, sum <font color='#5555FF'>=</font> <font color='#979000'>0</font>, two <font color='#5555FF'>=</font> <font color='#979000'>0</font>, diff <font color='#5555FF'>=</font> <font color='#979000'>0</font>, half <font color='#5555FF'>=</font> <font color='#979000'>0</font>, beta <font color='#5555FF'>=</font> <font color='#979000'>0</font>, gisq <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            integer knew <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            doublereal temp, suma, sumb, bsum, fopt;
            integer kopt <font color='#5555FF'>=</font> <font color='#979000'>0</font>, nptm;
            doublereal zero, curv;
            integer ksav;
            doublereal gqsq <font color='#5555FF'>=</font> <font color='#979000'>0</font>, dist <font color='#5555FF'>=</font> <font color='#979000'>0</font>, sumw <font color='#5555FF'>=</font> <font color='#979000'>0</font>, sumz <font color='#5555FF'>=</font> <font color='#979000'>0</font>, diffa <font color='#5555FF'>=</font> <font color='#979000'>0</font>, diffb <font color='#5555FF'>=</font> <font color='#979000'>0</font>, diffc <font color='#5555FF'>=</font> <font color='#979000'>0</font>, hdiag <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            integer kbase;
            doublereal alpha <font color='#5555FF'>=</font> <font color='#979000'>0</font>, delta <font color='#5555FF'>=</font> <font color='#979000'>0</font>, adelt <font color='#5555FF'>=</font> <font color='#979000'>0</font>, denom <font color='#5555FF'>=</font> <font color='#979000'>0</font>, fsave <font color='#5555FF'>=</font> <font color='#979000'>0</font>, bdtol <font color='#5555FF'>=</font> <font color='#979000'>0</font>, delsq <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            integer nresc, nfsav;
            doublereal ratio <font color='#5555FF'>=</font> <font color='#979000'>0</font>, dnorm <font color='#5555FF'>=</font> <font color='#979000'>0</font>, vquad <font color='#5555FF'>=</font> <font color='#979000'>0</font>, pqold <font color='#5555FF'>=</font> <font color='#979000'>0</font>, tenth <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            integer itest;
            doublereal sumpq, scaden;
            doublereal errbig, cauchy, fracsq, biglsq, densav;
            doublereal bdtest;
            doublereal crvmin, frhosq;
            doublereal distsq;
            integer ntrits;
            doublereal xoptsq;



            <font color='#009900'>/*     The arguments N, NPT, X, XL, XU, RHOBEG, RHOEND, IPRINT and MAXFUN */</font>
            <font color='#009900'>/*       are identical to the corresponding arguments in SUBROUTINE BOBYQA. */</font>
            <font color='#009900'>/*     XBASE holds a shift of origin that should reduce the contributions */</font>
            <font color='#009900'>/*       from rounding errors to values of the model and Lagrange functions. */</font>
            <font color='#009900'>/*     XPT is a two-dimensional array that holds the coordinates of the */</font>
            <font color='#009900'>/*       interpolation points relative to XBASE. */</font>
            <font color='#009900'>/*     FVAL holds the values of F at the interpolation points. */</font>
            <font color='#009900'>/*     XOPT is set to the displacement from XBASE of the trust region centre. */</font>
            <font color='#009900'>/*     GOPT holds the gradient of the quadratic model at XBASE+XOPT. */</font>
            <font color='#009900'>/*     HQ holds the explicit second derivatives of the quadratic model. */</font>
            <font color='#009900'>/*     PQ contains the parameters of the implicit second derivatives of the */</font>
            <font color='#009900'>/*       quadratic model. */</font>
            <font color='#009900'>/*     BMAT holds the last N columns of H. */</font>
            <font color='#009900'>/*     ZMAT holds the factorization of the leading NPT by NPT submatrix of H, */</font>
            <font color='#009900'>/*       this factorization being ZMAT times ZMAT^T, which provides both the */</font>
            <font color='#009900'>/*       correct rank and positive semi-definiteness. */</font>
            <font color='#009900'>/*     NDIM is the first dimension of BMAT and has the value NPT+N. */</font>
            <font color='#009900'>/*     SL and SU hold the differences XL-XBASE and XU-XBASE, respectively. */</font>
            <font color='#009900'>/*       All the components of every XOPT are going to satisfy the bounds */</font>
            <font color='#009900'>/*       SL(I) .LEQ. XOPT(I) .LEQ. SU(I), with appropriate equalities when */</font>
            <font color='#009900'>/*       XOPT is on a constraint boundary. */</font>
            <font color='#009900'>/*     XNEW is chosen by SUBROUTINE TRSBOX or ALTMOV. Usually XBASE+XNEW is the */</font>
            <font color='#009900'>/*       vector of variables for the next call of CALFUN. XNEW also satisfies */</font>
            <font color='#009900'>/*       the SL and SU constraints in the way that has just been mentioned. */</font>
            <font color='#009900'>/*     XALT is an alternative to XNEW, chosen by ALTMOV, that may replace XNEW */</font>
            <font color='#009900'>/*       in order to increase the denominator in the updating of UPDATE. */</font>
            <font color='#009900'>/*     D is reserved for a trial step from XOPT, which is usually XNEW-XOPT. */</font>
            <font color='#009900'>/*     VLAG contains the values of the Lagrange functions at a new point X. */</font>
            <font color='#009900'>/*       They are part of a product that requires VLAG to be of length NDIM. */</font>
            <font color='#009900'>/*     W is a one-dimensional array that is used for working space. Its length */</font>
            <font color='#009900'>/*       must be at least 3*NDIM = 3*(NPT+N). */</font>

            <font color='#009900'>/*     Set some constants. */</font>

            <font color='#009900'>/* Parameter adjustments */</font>
            zmat_dim1 <font color='#5555FF'>=</font> npt;
            zmat_offset <font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>+</font> zmat_dim1;
            zmat <font color='#5555FF'>-</font><font color='#5555FF'>=</font> zmat_offset;
            xpt_dim1 <font color='#5555FF'>=</font> npt;
            xpt_offset <font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>+</font> xpt_dim1;
            xpt <font color='#5555FF'>-</font><font color='#5555FF'>=</font> xpt_offset;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>x;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>xl;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>xu;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>xbase;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>fval;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>xopt;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>gopt;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>hq;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>pq;
            bmat_dim1 <font color='#5555FF'>=</font> ndim;
            bmat_offset <font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>+</font> bmat_dim1;
            bmat <font color='#5555FF'>-</font><font color='#5555FF'>=</font> bmat_offset;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>sl;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>su;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>xnew;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>xalt;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>d__;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>vlag;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>w;

            <font color='#009900'>/* Function Body */</font>
            half <font color='#5555FF'>=</font> .<font color='#979000'>5</font>;
            one <font color='#5555FF'>=</font> <font color='#979000'>1.</font>;
            ten <font color='#5555FF'>=</font> <font color='#979000'>10.</font>;
            tenth <font color='#5555FF'>=</font> .<font color='#979000'>1</font>;
            two <font color='#5555FF'>=</font> <font color='#979000'>2.</font>;
            zero <font color='#5555FF'>=</font> <font color='#979000'>0.</font>;
            np <font color='#5555FF'>=</font> n <font color='#5555FF'>+</font> <font color='#979000'>1</font>;
            nptm <font color='#5555FF'>=</font> npt <font color='#5555FF'>-</font> np;
            nh <font color='#5555FF'>=</font> n <font color='#5555FF'>*</font> np <font color='#5555FF'>/</font> <font color='#979000'>2</font>;

            <font color='#009900'>/*     The call of PRELIM sets the elements of XBASE, XPT, FVAL, GOPT, HQ, PQ, */</font>
            <font color='#009900'>/*     BMAT and ZMAT for the first iteration, with the corresponding values of */</font>
            <font color='#009900'>/*     of NF and KOPT, which are the number of calls of CALFUN so far and the */</font>
            <font color='#009900'>/*     index of the interpolation point at the trust region centre. Then the */</font>
            <font color='#009900'>/*     initial XOPT is set too. The branch to label 720 occurs if MAXFUN is */</font>
            <font color='#009900'>/*     less than NPT. GOPT will be updated if KOPT is different from KBASE. */</font>

            <font color='#BB00BB'>prelim_</font><font face='Lucida Console'>(</font>calfun, n, npt, <font color='#5555FF'>&amp;</font>x[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>xl[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>xu[<font color='#979000'>1</font>], rhobeg, maxfun, <font color='#5555FF'>&amp;</font>xbase[<font color='#979000'>1</font>], 
                    <font color='#5555FF'>&amp;</font>xpt[xpt_offset], <font color='#5555FF'>&amp;</font>fval[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>gopt[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>hq[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>pq[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>bmat[bmat_offset], 
                    <font color='#5555FF'>&amp;</font>zmat[zmat_offset], ndim, <font color='#5555FF'>&amp;</font>sl[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>su[<font color='#979000'>1</font>], nf, kopt<font face='Lucida Console'>)</font>;
            xoptsq <font color='#5555FF'>=</font> zero;
            i__1 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                xopt[i__] <font color='#5555FF'>=</font> xpt[kopt <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> xpt_dim1];
                <font color='#009900'>/* L10: */</font>
                <font color='#009900'>/* Computing 2nd power */</font>
                d__1 <font color='#5555FF'>=</font> xopt[i__];
                xoptsq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
            <b>}</b>
            fsave <font color='#5555FF'>=</font> fval[<font color='#979000'>1</font>];
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>nf <font color='#5555FF'>&lt;</font> npt<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>throw</font> <font color='#BB00BB'>bobyqa_failure</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Return from BOBYQA because the objective function has been called max_f_evals times.</font>"<font face='Lucida Console'>)</font>;
                <font color='#009900'>//goto L720;
</font>            <b>}</b>
            kbase <font color='#5555FF'>=</font> <font color='#979000'>1</font>;

            <font color='#009900'>/*     Complete the settings that are required for the iterative procedure. */</font>

            rho <font color='#5555FF'>=</font> rhobeg;
            delta <font color='#5555FF'>=</font> rho;
            nresc <font color='#5555FF'>=</font> nf;
            ntrits <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            diffa <font color='#5555FF'>=</font> zero;
            diffb <font color='#5555FF'>=</font> zero;
            itest <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            nfsav <font color='#5555FF'>=</font> nf;

            <font color='#009900'>/*     Update GOPT if necessary before the first iteration and after each */</font>
            <font color='#009900'>/*     call of RESCUE that makes a call of CALFUN. */</font>

L20:
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>kopt <font color='#5555FF'>!</font><font color='#5555FF'>=</font> kbase<font face='Lucida Console'>)</font> <b>{</b>
                ih <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                i__1 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                    i__2 <font color='#5555FF'>=</font> j;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#5555FF'>+</font><font color='#5555FF'>+</font>ih;
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>&lt;</font> j<font face='Lucida Console'>)</font> <b>{</b>
                            gopt[j] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> hq[ih] <font color='#5555FF'>*</font> xopt[i__];
                        <b>}</b>
                        <font color='#009900'>/* L30: */</font>
                        gopt[i__] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> hq[ih] <font color='#5555FF'>*</font> xopt[j];
                    <b>}</b>
                <b>}</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>nf <font color='#5555FF'>&gt;</font> npt<font face='Lucida Console'>)</font> <b>{</b>
                    i__2 <font color='#5555FF'>=</font> npt;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                        temp <font color='#5555FF'>=</font> zero;
                        i__1 <font color='#5555FF'>=</font> n;
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                            <font color='#009900'>/* L40: */</font>
                            temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> xpt[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>*</font> xopt[j];
                        <b>}</b>
                        temp <font color='#5555FF'>=</font> pq[k] <font color='#5555FF'>*</font> temp;
                        i__1 <font color='#5555FF'>=</font> n;
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                            <font color='#009900'>/* L50: */</font>
                            gopt[i__] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp <font color='#5555FF'>*</font> xpt[k <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> xpt_dim1];
                        <b>}</b>
                    <b>}</b>
                <b>}</b>
            <b>}</b>

            <font color='#009900'>/*     Generate the next point in the trust region that provides a small value */</font>
            <font color='#009900'>/*     of the quadratic model subject to the constraints on the variables. */</font>
            <font color='#009900'>/*     The integer NTRITS is set to the number "trust region" iterations that */</font>
            <font color='#009900'>/*     have occurred since the last "alternative" iteration. If the length */</font>
            <font color='#009900'>/*     of XNEW-XOPT is less than HALF*RHO, however, then there is a branch to */</font>
            <font color='#009900'>/*     label 650 or 680 with NTRITS=-1, instead of calculating F at XNEW. */</font>

L60:
            <font color='#BB00BB'>trsbox_</font><font face='Lucida Console'>(</font>n, npt, <font color='#5555FF'>&amp;</font>xpt[xpt_offset], <font color='#5555FF'>&amp;</font>xopt[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>gopt[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>hq[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>pq[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>sl[<font color='#979000'>1</font>], 
                    <font color='#5555FF'>&amp;</font>su[<font color='#979000'>1</font>], delta, <font color='#5555FF'>&amp;</font>xnew[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>d__[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>w[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>w[np], <font color='#5555FF'>&amp;</font>w[np <font color='#5555FF'>+</font> n],
                    <font color='#5555FF'>&amp;</font>w[np <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font>n <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>], <font color='#5555FF'>&amp;</font>w[np <font color='#5555FF'>+</font> n <font color='#5555FF'>*</font> <font color='#979000'>3</font>], <font color='#5555FF'>&amp;</font>dsq, <font color='#5555FF'>&amp;</font>crvmin<font face='Lucida Console'>)</font>;
            <font color='#009900'>/* Computing MIN */</font>
            d__1 <font color='#5555FF'>=</font> delta, d__2 <font color='#5555FF'>=</font> std::<font color='#BB00BB'>sqrt</font><font face='Lucida Console'>(</font>dsq<font face='Lucida Console'>)</font>;
            dnorm <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>dnorm <font color='#5555FF'>&lt;</font> half <font color='#5555FF'>*</font> rho<font face='Lucida Console'>)</font> <b>{</b>
                ntrits <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
                <font color='#009900'>/* Computing 2nd power */</font>
                d__1 <font color='#5555FF'>=</font> ten <font color='#5555FF'>*</font> rho;
                distsq <font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>nf <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> nfsav <font color='#5555FF'>+</font> <font color='#979000'>2</font><font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#0000FF'>goto</font> L650;
                <b>}</b>

                <font color='#009900'>/*     The following choice between labels 650 and 680 depends on whether or */</font>
                <font color='#009900'>/*     not our work with the current RHO seems to be complete. Either RHO is */</font>
                <font color='#009900'>/*     decreased or termination occurs if the errors in the quadratic model at */</font>
                <font color='#009900'>/*     the last three interpolation points compare favourably with predictions */</font>
                <font color='#009900'>/*     of likely improvements to the model within distance HALF*RHO of XOPT. */</font>

                <font color='#009900'>/* Computing MAX */</font>
                d__1 <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>diffa,diffb<font face='Lucida Console'>)</font>;
                errbig <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__1,diffc<font face='Lucida Console'>)</font>;
                frhosq <font color='#5555FF'>=</font> rho <font color='#5555FF'>*</font> .<font color='#979000'>125</font> <font color='#5555FF'>*</font> rho;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>crvmin <font color='#5555FF'>&gt;</font> zero <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> errbig <font color='#5555FF'>&gt;</font> frhosq <font color='#5555FF'>*</font> crvmin<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#0000FF'>goto</font> L650;
                <b>}</b>
                bdtol <font color='#5555FF'>=</font> errbig <font color='#5555FF'>/</font> rho;
                i__1 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                    bdtest <font color='#5555FF'>=</font> bdtol;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xnew[j] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> sl[j]<font face='Lucida Console'>)</font> <b>{</b>
                        bdtest <font color='#5555FF'>=</font> w[j];
                    <b>}</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xnew[j] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> su[j]<font face='Lucida Console'>)</font> <b>{</b>
                        bdtest <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>w[j];
                    <b>}</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>bdtest <font color='#5555FF'>&lt;</font> bdtol<font face='Lucida Console'>)</font> <b>{</b>
                        curv <font color='#5555FF'>=</font> hq[<font face='Lucida Console'>(</font>j <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> j<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> <font color='#979000'>2</font>];
                        i__2 <font color='#5555FF'>=</font> npt;
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                            <font color='#009900'>/* L70: */</font>
                            <font color='#009900'>/* Computing 2nd power */</font>
                            d__1 <font color='#5555FF'>=</font> xpt[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1];
                            curv <font color='#5555FF'>+</font><font color='#5555FF'>=</font> pq[k] <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>d__1 <font color='#5555FF'>*</font> d__1<font face='Lucida Console'>)</font>;
                        <b>}</b>
                        bdtest <font color='#5555FF'>+</font><font color='#5555FF'>=</font> half <font color='#5555FF'>*</font> curv <font color='#5555FF'>*</font> rho;
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>bdtest <font color='#5555FF'>&lt;</font> bdtol<font face='Lucida Console'>)</font> <b>{</b>
                            <font color='#0000FF'>goto</font> L650;
                        <b>}</b>
                    <b>}</b>
                    <font color='#009900'>/* L80: */</font>
                <b>}</b>
                <font color='#0000FF'>goto</font> L680;
            <b>}</b>
            <font color='#5555FF'>+</font><font color='#5555FF'>+</font>ntrits;

            <font color='#009900'>/*     Severe cancellation is likely to occur if XOPT is too far from XBASE. */</font>
            <font color='#009900'>/*     If the following test holds, then XBASE is shifted so that XOPT becomes */</font>
            <font color='#009900'>/*     zero. The appropriate changes are made to BMAT and to the second */</font>
            <font color='#009900'>/*     derivatives of the current model, beginning with the changes to BMAT */</font>
            <font color='#009900'>/*     that do not depend on ZMAT. VLAG is used temporarily for working space. */</font>

L90:
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>dsq <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> xoptsq <font color='#5555FF'>*</font> .<font color='#979000'>001</font><font face='Lucida Console'>)</font> <b>{</b>
                fracsq <font color='#5555FF'>=</font> xoptsq <font color='#5555FF'>*</font> .<font color='#979000'>25</font>;
                sumpq <font color='#5555FF'>=</font> zero;
                i__1 <font color='#5555FF'>=</font> npt;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                    sumpq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> pq[k];
                    sum <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>half <font color='#5555FF'>*</font> xoptsq;
                    i__2 <font color='#5555FF'>=</font> n;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#009900'>/* L100: */</font>
                        sum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> xpt[k <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>*</font> xopt[i__];
                    <b>}</b>
                    w[npt <font color='#5555FF'>+</font> k] <font color='#5555FF'>=</font> sum;
                    temp <font color='#5555FF'>=</font> fracsq <font color='#5555FF'>-</font> half <font color='#5555FF'>*</font> sum;
                    i__2 <font color='#5555FF'>=</font> n;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                        w[i__] <font color='#5555FF'>=</font> bmat[k <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> bmat_dim1];
                        vlag[i__] <font color='#5555FF'>=</font> sum <font color='#5555FF'>*</font> xpt[k <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>+</font> temp <font color='#5555FF'>*</font> xopt[i__];
                        ip <font color='#5555FF'>=</font> npt <font color='#5555FF'>+</font> i__;
                        i__3 <font color='#5555FF'>=</font> i__;
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__3; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                            <font color='#009900'>/* L110: */</font>
                            bmat[ip <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>=</font> bmat[ip <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>+</font> w[
                                i__] <font color='#5555FF'>*</font> vlag[j] <font color='#5555FF'>+</font> vlag[i__] <font color='#5555FF'>*</font> w[j];
                        <b>}</b>
                    <b>}</b>
                <b>}</b>

                <font color='#009900'>/*     Then the revisions of BMAT that depend on ZMAT are calculated. */</font>

                i__3 <font color='#5555FF'>=</font> nptm;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>jj <font color='#5555FF'>=</font> <font color='#979000'>1</font>; jj <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__3; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>jj<font face='Lucida Console'>)</font> <b>{</b>
                    sumz <font color='#5555FF'>=</font> zero;
                    sumw <font color='#5555FF'>=</font> zero;
                    i__2 <font color='#5555FF'>=</font> npt;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                        sumz <font color='#5555FF'>+</font><font color='#5555FF'>=</font> zmat[k <font color='#5555FF'>+</font> jj <font color='#5555FF'>*</font> zmat_dim1];
                        vlag[k] <font color='#5555FF'>=</font> w[npt <font color='#5555FF'>+</font> k] <font color='#5555FF'>*</font> zmat[k <font color='#5555FF'>+</font> jj <font color='#5555FF'>*</font> zmat_dim1];
                        <font color='#009900'>/* L120: */</font>
                        sumw <font color='#5555FF'>+</font><font color='#5555FF'>=</font> vlag[k];
                    <b>}</b>
                    i__2 <font color='#5555FF'>=</font> n;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                        sum <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>fracsq <font color='#5555FF'>*</font> sumz <font color='#5555FF'>-</font> half <font color='#5555FF'>*</font> sumw<font face='Lucida Console'>)</font> <font color='#5555FF'>*</font> xopt[j];
                        i__1 <font color='#5555FF'>=</font> npt;
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                            <font color='#009900'>/* L130: */</font>
                            sum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> vlag[k] <font color='#5555FF'>*</font> xpt[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1];
                        <b>}</b>
                        w[j] <font color='#5555FF'>=</font> sum;
                        i__1 <font color='#5555FF'>=</font> npt;
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                            <font color='#009900'>/* L140: */</font>
                            bmat[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> sum <font color='#5555FF'>*</font> zmat[k <font color='#5555FF'>+</font> jj <font color='#5555FF'>*</font> zmat_dim1];
                        <b>}</b>
                    <b>}</b>
                    i__1 <font color='#5555FF'>=</font> n;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                        ip <font color='#5555FF'>=</font> i__ <font color='#5555FF'>+</font> npt;
                        temp <font color='#5555FF'>=</font> w[i__];
                        i__2 <font color='#5555FF'>=</font> i__;
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                            <font color='#009900'>/* L150: */</font>
                            bmat[ip <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp <font color='#5555FF'>*</font> w[j];
                        <b>}</b>
                    <b>}</b>
                <b>}</b>

                <font color='#009900'>/*     The following instructions complete the shift, including the changes */</font>
                <font color='#009900'>/*     to the second derivative parameters of the quadratic model. */</font>

                ih <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                i__2 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                    w[j] <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>half <font color='#5555FF'>*</font> sumpq <font color='#5555FF'>*</font> xopt[j];
                    i__1 <font color='#5555FF'>=</font> npt;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                        w[j] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> pq[k] <font color='#5555FF'>*</font> xpt[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1];
                        <font color='#009900'>/* L160: */</font>
                        xpt[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>-</font><font color='#5555FF'>=</font> xopt[j];
                    <b>}</b>
                    i__1 <font color='#5555FF'>=</font> j;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#5555FF'>+</font><font color='#5555FF'>+</font>ih;
                        hq[ih] <font color='#5555FF'>=</font> hq[ih] <font color='#5555FF'>+</font> w[i__] <font color='#5555FF'>*</font> xopt[j] <font color='#5555FF'>+</font> xopt[i__] <font color='#5555FF'>*</font> w[j];
                        <font color='#009900'>/* L170: */</font>
                        bmat[npt <font color='#5555FF'>+</font> i__ <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>=</font> bmat[npt <font color='#5555FF'>+</font> j <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> 
                            bmat_dim1];
                    <b>}</b>
                <b>}</b>
                i__1 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                    xbase[i__] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> xopt[i__];
                    xnew[i__] <font color='#5555FF'>-</font><font color='#5555FF'>=</font> xopt[i__];
                    sl[i__] <font color='#5555FF'>-</font><font color='#5555FF'>=</font> xopt[i__];
                    su[i__] <font color='#5555FF'>-</font><font color='#5555FF'>=</font> xopt[i__];
                    <font color='#009900'>/* L180: */</font>
                    xopt[i__] <font color='#5555FF'>=</font> zero;
                <b>}</b>
                xoptsq <font color='#5555FF'>=</font> zero;
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ntrits <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>goto</font> L210;
            <b>}</b>
            <font color='#0000FF'>goto</font> L230;

            <font color='#009900'>/*     XBASE is also moved to XOPT by a call of RESCUE. This calculation is */</font>
            <font color='#009900'>/*     more expensive than the previous shift, because new matrices BMAT and */</font>
            <font color='#009900'>/*     ZMAT are generated from scratch, which may include the replacement of */</font>
            <font color='#009900'>/*     interpolation points whose positions seem to be causing near linear */</font>
            <font color='#009900'>/*     dependence in the interpolation conditions. Therefore RESCUE is called */</font>
            <font color='#009900'>/*     only if rounding errors have reduced by at least a factor of two the */</font>
            <font color='#009900'>/*     denominator of the formula for updating the H matrix. It provides a */</font>
            <font color='#009900'>/*     useful safeguard, but is not invoked in most applications of BOBYQA. */</font>

L190:
            nfsav <font color='#5555FF'>=</font> nf;
            kbase <font color='#5555FF'>=</font> kopt;
            <font color='#BB00BB'>rescue_</font><font face='Lucida Console'>(</font>calfun, n, npt, <font color='#5555FF'>&amp;</font>xl[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>xu[<font color='#979000'>1</font>], maxfun, <font color='#5555FF'>&amp;</font>xbase[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>xpt[
                    xpt_offset], <font color='#5555FF'>&amp;</font>fval[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>xopt[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>gopt[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>hq[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>pq[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>bmat[
                    bmat_offset], <font color='#5555FF'>&amp;</font>zmat[zmat_offset], ndim, <font color='#5555FF'>&amp;</font>sl[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>su[<font color='#979000'>1</font>], nf, delta, 
                    kopt, <font color='#5555FF'>&amp;</font>vlag[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>w[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>w[n <font color='#5555FF'>+</font> np], <font color='#5555FF'>&amp;</font>w[ndim <font color='#5555FF'>+</font> np]<font face='Lucida Console'>)</font>;

            <font color='#009900'>/*     XOPT is updated now in case the branch below to label 720 is taken. */</font>
            <font color='#009900'>/*     Any updating of GOPT occurs after the branch below to label 20, which */</font>
            <font color='#009900'>/*     leads to a trust region iteration as does the branch to label 60. */</font>

            xoptsq <font color='#5555FF'>=</font> zero;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>kopt <font color='#5555FF'>!</font><font color='#5555FF'>=</font> kbase<font face='Lucida Console'>)</font> <b>{</b>
                i__1 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                    xopt[i__] <font color='#5555FF'>=</font> xpt[kopt <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> xpt_dim1];
                    <font color='#009900'>/* L200: */</font>
                    <font color='#009900'>/* Computing 2nd power */</font>
                    d__1 <font color='#5555FF'>=</font> xopt[i__];
                    xoptsq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>nf <font color='#5555FF'>&lt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                nf <font color='#5555FF'>=</font> maxfun;
                <font color='#0000FF'>throw</font> <font color='#BB00BB'>bobyqa_failure</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Return from BOBYQA because the objective function has been called max_f_evals times.</font>"<font face='Lucida Console'>)</font>;
                <font color='#009900'>//goto L720;
</font>            <b>}</b>
            nresc <font color='#5555FF'>=</font> nf;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>nfsav <font color='#5555FF'>&lt;</font> nf<font face='Lucida Console'>)</font> <b>{</b>
                nfsav <font color='#5555FF'>=</font> nf;
                <font color='#0000FF'>goto</font> L20;
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ntrits <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>goto</font> L60;
            <b>}</b>

            <font color='#009900'>/*     Pick two alternative vectors of variables, relative to XBASE, that */</font>
            <font color='#009900'>/*     are suitable as new positions of the KNEW-th interpolation point. */</font>
            <font color='#009900'>/*     Firstly, XNEW is set to the point on a line through XOPT and another */</font>
            <font color='#009900'>/*     interpolation point that minimizes the predicted value of the next */</font>
            <font color='#009900'>/*     denominator, subject to ||XNEW - XOPT|| .LEQ. ADELT and to the SL */</font>
            <font color='#009900'>/*     and SU bounds. Secondly, XALT is set to the best feasible point on */</font>
            <font color='#009900'>/*     a constrained version of the Cauchy step of the KNEW-th Lagrange */</font>
            <font color='#009900'>/*     function, the corresponding value of the square of this function */</font>
            <font color='#009900'>/*     being returned in CAUCHY. The choice between these alternatives is */</font>
            <font color='#009900'>/*     going to be made when the denominator is calculated. */</font>

L210:
            <font color='#BB00BB'>altmov_</font><font face='Lucida Console'>(</font>n, npt, <font color='#5555FF'>&amp;</font>xpt[xpt_offset], <font color='#5555FF'>&amp;</font>xopt[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>bmat[bmat_offset], <font color='#5555FF'>&amp;</font>zmat[zmat_offset], 
                    ndim, <font color='#5555FF'>&amp;</font>sl[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>su[<font color='#979000'>1</font>], kopt, knew, adelt, <font color='#5555FF'>&amp;</font>xnew[<font color='#979000'>1</font>], 
                    <font color='#5555FF'>&amp;</font>xalt[<font color='#979000'>1</font>], alpha, cauchy, <font color='#5555FF'>&amp;</font>w[<font color='#979000'>1</font>], <font color='#5555FF'>&amp;</font>w[np], <font color='#5555FF'>&amp;</font>w[ndim <font color='#5555FF'>+</font> <font color='#979000'>1</font>]<font face='Lucida Console'>)</font>;
            i__1 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#009900'>/* L220: */</font>
                d__[i__] <font color='#5555FF'>=</font> xnew[i__] <font color='#5555FF'>-</font> xopt[i__];
            <b>}</b>

            <font color='#009900'>/*     Calculate VLAG and BETA for the current choice of D. The scalar */</font>
            <font color='#009900'>/*     product of D with XPT(K,.) is going to be held in W(NPT+K) for */</font>
            <font color='#009900'>/*     use when VQUAD is calculated. */</font>

L230:
            i__1 <font color='#5555FF'>=</font> npt;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                suma <font color='#5555FF'>=</font> zero;
                sumb <font color='#5555FF'>=</font> zero;
                sum <font color='#5555FF'>=</font> zero;
                i__2 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                    suma <font color='#5555FF'>+</font><font color='#5555FF'>=</font> xpt[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>*</font> d__[j];
                    sumb <font color='#5555FF'>+</font><font color='#5555FF'>=</font> xpt[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>*</font> xopt[j];
                    <font color='#009900'>/* L240: */</font>
                    sum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> bmat[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>*</font> d__[j];
                <b>}</b>
                w[k] <font color='#5555FF'>=</font> suma <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>half <font color='#5555FF'>*</font> suma <font color='#5555FF'>+</font> sumb<font face='Lucida Console'>)</font>;
                vlag[k] <font color='#5555FF'>=</font> sum;
                <font color='#009900'>/* L250: */</font>
                w[npt <font color='#5555FF'>+</font> k] <font color='#5555FF'>=</font> suma;
            <b>}</b>
            beta <font color='#5555FF'>=</font> zero;
            i__1 <font color='#5555FF'>=</font> nptm;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>jj <font color='#5555FF'>=</font> <font color='#979000'>1</font>; jj <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>jj<font face='Lucida Console'>)</font> <b>{</b>
                sum <font color='#5555FF'>=</font> zero;
                i__2 <font color='#5555FF'>=</font> npt;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L260: */</font>
                    sum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> zmat[k <font color='#5555FF'>+</font> jj <font color='#5555FF'>*</font> zmat_dim1] <font color='#5555FF'>*</font> w[k];
                <b>}</b>
                beta <font color='#5555FF'>-</font><font color='#5555FF'>=</font> sum <font color='#5555FF'>*</font> sum;
                i__2 <font color='#5555FF'>=</font> npt;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L270: */</font>
                    vlag[k] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> sum <font color='#5555FF'>*</font> zmat[k <font color='#5555FF'>+</font> jj <font color='#5555FF'>*</font> zmat_dim1];
                <b>}</b>
            <b>}</b>
            dsq <font color='#5555FF'>=</font> zero;
            bsum <font color='#5555FF'>=</font> zero;
            dx <font color='#5555FF'>=</font> zero;
            i__2 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#009900'>/* Computing 2nd power */</font>
                d__1 <font color='#5555FF'>=</font> d__[j];
                dsq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                sum <font color='#5555FF'>=</font> zero;
                i__1 <font color='#5555FF'>=</font> npt;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L280: */</font>
                    sum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> w[k] <font color='#5555FF'>*</font> bmat[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1];
                <b>}</b>
                bsum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> sum <font color='#5555FF'>*</font> d__[j];
                jp <font color='#5555FF'>=</font> npt <font color='#5555FF'>+</font> j;
                i__1 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L290: */</font>
                    sum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> bmat[jp <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>*</font> d__[i__];
                <b>}</b>
                vlag[jp] <font color='#5555FF'>=</font> sum;
                bsum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> sum <font color='#5555FF'>*</font> d__[j];
                <font color='#009900'>/* L300: */</font>
                dx <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__[j] <font color='#5555FF'>*</font> xopt[j];
            <b>}</b>
            beta <font color='#5555FF'>=</font> dx <font color='#5555FF'>*</font> dx <font color='#5555FF'>+</font> dsq <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>xoptsq <font color='#5555FF'>+</font> dx <font color='#5555FF'>+</font> dx <font color='#5555FF'>+</font> half <font color='#5555FF'>*</font> dsq<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> beta <font color='#5555FF'>-</font> bsum;
            vlag[kopt] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> one;

            <font color='#009900'>/*     If NTRITS is zero, the denominator may be increased by replacing */</font>
            <font color='#009900'>/*     the step D of ALTMOV by a Cauchy step. Then RESCUE may be called if */</font>
            <font color='#009900'>/*     rounding errors have damaged the chosen denominator. */</font>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ntrits <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                <font color='#009900'>/* Computing 2nd power */</font>
                d__1 <font color='#5555FF'>=</font> vlag[knew];
                denom <font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1 <font color='#5555FF'>+</font> alpha <font color='#5555FF'>*</font> beta;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>denom <font color='#5555FF'>&lt;</font> cauchy <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> cauchy <font color='#5555FF'>&gt;</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    i__2 <font color='#5555FF'>=</font> n;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                        xnew[i__] <font color='#5555FF'>=</font> xalt[i__];
                        <font color='#009900'>/* L310: */</font>
                        d__[i__] <font color='#5555FF'>=</font> xnew[i__] <font color='#5555FF'>-</font> xopt[i__];
                    <b>}</b>
                    cauchy <font color='#5555FF'>=</font> zero;
                    <font color='#0000FF'>goto</font> L230;
                <b>}</b>
                <font color='#009900'>/* Computing 2nd power */</font>
                d__1 <font color='#5555FF'>=</font> vlag[knew];
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>denom <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> half <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>d__1 <font color='#5555FF'>*</font> d__1<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>nf <font color='#5555FF'>&gt;</font> nresc<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#0000FF'>goto</font> L190;
                    <b>}</b>
                    <font color='#0000FF'>throw</font> <font color='#BB00BB'>bobyqa_failure</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Return from BOBYQA because of much cancellation in a denominator.</font>"<font face='Lucida Console'>)</font>;
                    <font color='#009900'>//goto L720;
</font>                <b>}</b>

                <font color='#009900'>/*     Alternatively, if NTRITS is positive, then set KNEW to the index of */</font>
                <font color='#009900'>/*     the next interpolation point to be deleted to make room for a trust */</font>
                <font color='#009900'>/*     region step. Again RESCUE may be called if rounding errors have damaged */</font>
                <font color='#009900'>/*     the chosen denominator, which is the reason for attempting to select */</font>
                <font color='#009900'>/*     KNEW before calculating the next value of the objective function. */</font>

            <b>}</b> <font color='#0000FF'>else</font> <b>{</b>
                delsq <font color='#5555FF'>=</font> delta <font color='#5555FF'>*</font> delta;
                scaden <font color='#5555FF'>=</font> zero;
                biglsq <font color='#5555FF'>=</font> zero;
                knew <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                i__2 <font color='#5555FF'>=</font> npt;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font><font color='#5555FF'>=</font> kopt<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#0000FF'>goto</font> L350;
                    <b>}</b>
                    hdiag <font color='#5555FF'>=</font> zero;
                    i__1 <font color='#5555FF'>=</font> nptm;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>jj <font color='#5555FF'>=</font> <font color='#979000'>1</font>; jj <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>jj<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#009900'>/* L330: */</font>
                        <font color='#009900'>/* Computing 2nd power */</font>
                        d__1 <font color='#5555FF'>=</font> zmat[k <font color='#5555FF'>+</font> jj <font color='#5555FF'>*</font> zmat_dim1];
                        hdiag <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                    <b>}</b>
                    <font color='#009900'>/* Computing 2nd power */</font>
                    d__1 <font color='#5555FF'>=</font> vlag[k];
                    den <font color='#5555FF'>=</font> beta <font color='#5555FF'>*</font> hdiag <font color='#5555FF'>+</font> d__1 <font color='#5555FF'>*</font> d__1;
                    distsq <font color='#5555FF'>=</font> zero;
                    i__1 <font color='#5555FF'>=</font> n;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#009900'>/* L340: */</font>
                        <font color='#009900'>/* Computing 2nd power */</font>
                        d__1 <font color='#5555FF'>=</font> xpt[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>-</font> xopt[j];
                        distsq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                    <b>}</b>
                    <font color='#009900'>/* Computing MAX */</font>
                    <font color='#009900'>/* Computing 2nd power */</font>
                    d__3 <font color='#5555FF'>=</font> distsq <font color='#5555FF'>/</font> delsq;
                    d__1 <font color='#5555FF'>=</font> one, d__2 <font color='#5555FF'>=</font> d__3 <font color='#5555FF'>*</font> d__3;
                    temp <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp <font color='#5555FF'>*</font> den <font color='#5555FF'>&gt;</font> scaden<font face='Lucida Console'>)</font> <b>{</b>
                        scaden <font color='#5555FF'>=</font> temp <font color='#5555FF'>*</font> den;
                        knew <font color='#5555FF'>=</font> k;
                        denom <font color='#5555FF'>=</font> den;
                    <b>}</b>
                    <font color='#009900'>/* Computing MAX */</font>
                    <font color='#009900'>/* Computing 2nd power */</font>
                    d__3 <font color='#5555FF'>=</font> vlag[k];
                    d__1 <font color='#5555FF'>=</font> biglsq, d__2 <font color='#5555FF'>=</font> temp <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>d__3 <font color='#5555FF'>*</font> d__3<font face='Lucida Console'>)</font>;
                    biglsq <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
L350:
                    ;
                <b>}</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>scaden <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> half <font color='#5555FF'>*</font> biglsq<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>nf <font color='#5555FF'>&gt;</font> nresc<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#0000FF'>goto</font> L190;
                    <b>}</b>
                    <font color='#0000FF'>throw</font> <font color='#BB00BB'>bobyqa_failure</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Return from BOBYQA because of much cancellation in a denominator.</font>"<font face='Lucida Console'>)</font>;
                    <font color='#009900'>//goto L720;
</font>                <b>}</b>
            <b>}</b>

            <font color='#009900'>/*     Put the variables for the next calculation of the objective function */</font>
            <font color='#009900'>/*       in XNEW, with any adjustments for the bounds. */</font>


            <font color='#009900'>/*     Calculate the value of the objective function at XBASE+XNEW, unless */</font>
            <font color='#009900'>/*       the limit on the number of calculations of F has been reached. */</font>

L360:
            i__2 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#009900'>/* Computing MIN */</font>
                <font color='#009900'>/* Computing MAX */</font>
                d__3 <font color='#5555FF'>=</font> xl[i__], d__4 <font color='#5555FF'>=</font> xbase[i__] <font color='#5555FF'>+</font> xnew[i__];
                d__1 <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__3,d__4<font face='Lucida Console'>)</font>, d__2 <font color='#5555FF'>=</font> xu[i__];
                x[i__] <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xnew[i__] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> sl[i__]<font face='Lucida Console'>)</font> <b>{</b>
                    x[i__] <font color='#5555FF'>=</font> xl[i__];
                <b>}</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xnew[i__] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> su[i__]<font face='Lucida Console'>)</font> <b>{</b>
                    x[i__] <font color='#5555FF'>=</font> xu[i__];
                <b>}</b>
                <font color='#009900'>/* L380: */</font>
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>nf <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> maxfun<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>throw</font> <font color='#BB00BB'>bobyqa_failure</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Return from BOBYQA because the objective function has been called max_f_evals times.</font>"<font face='Lucida Console'>)</font>;
                <font color='#009900'>//goto L720;
</font>            <b>}</b>
            <font color='#5555FF'>+</font><font color='#5555FF'>+</font>nf;
            f <font color='#5555FF'>=</font> <font color='#BB00BB'>calfun</font><font face='Lucida Console'>(</font><font color='#BB00BB'>mat</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>x[<font color='#979000'>1</font>], n<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ntrits <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font> <b>{</b>
                fsave <font color='#5555FF'>=</font> f;
                <font color='#0000FF'>goto</font> L720;
            <b>}</b>

            <font color='#009900'>/*     Use the quadratic model to predict the change in F due to the step D, */</font>
            <font color='#009900'>/*       and set DIFF to the error of this prediction. */</font>

            fopt <font color='#5555FF'>=</font> fval[kopt];
            vquad <font color='#5555FF'>=</font> zero;
            ih <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            i__2 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                vquad <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__[j] <font color='#5555FF'>*</font> gopt[j];
                i__1 <font color='#5555FF'>=</font> j;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#5555FF'>+</font><font color='#5555FF'>+</font>ih;
                    temp <font color='#5555FF'>=</font> d__[i__] <font color='#5555FF'>*</font> d__[j];
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font face='Lucida Console'>)</font> <b>{</b>
                        temp <font color='#5555FF'>=</font> half <font color='#5555FF'>*</font> temp;
                    <b>}</b>
                    <font color='#009900'>/* L410: */</font>
                    vquad <font color='#5555FF'>+</font><font color='#5555FF'>=</font> hq[ih] <font color='#5555FF'>*</font> temp;
                <b>}</b>
            <b>}</b>
            i__1 <font color='#5555FF'>=</font> npt;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#009900'>/* L420: */</font>
                <font color='#009900'>/* Computing 2nd power */</font>
                d__1 <font color='#5555FF'>=</font> w[npt <font color='#5555FF'>+</font> k];
                vquad <font color='#5555FF'>+</font><font color='#5555FF'>=</font> half <font color='#5555FF'>*</font> pq[k] <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>d__1 <font color='#5555FF'>*</font> d__1<font face='Lucida Console'>)</font>;
            <b>}</b>
            diff <font color='#5555FF'>=</font> f <font color='#5555FF'>-</font> fopt <font color='#5555FF'>-</font> vquad;
            diffc <font color='#5555FF'>=</font> diffb;
            diffb <font color='#5555FF'>=</font> diffa;
            diffa <font color='#5555FF'>=</font> std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>diff<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>dnorm <font color='#5555FF'>&gt;</font> rho<font face='Lucida Console'>)</font> <b>{</b>
                nfsav <font color='#5555FF'>=</font> nf;
            <b>}</b>

            <font color='#009900'>/*     Pick the next value of DELTA after a trust region step. */</font>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ntrits <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>vquad <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#0000FF'>throw</font> <font color='#BB00BB'>bobyqa_failure</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Return from BOBYQA because a trust region step has failed to reduce Q.</font>"<font face='Lucida Console'>)</font>;
                    <font color='#009900'>//goto L720;
</font>                <b>}</b>
                ratio <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>f <font color='#5555FF'>-</font> fopt<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> vquad;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ratio <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> tenth<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* Computing MIN */</font>
                    d__1 <font color='#5555FF'>=</font> half <font color='#5555FF'>*</font> delta;
                    delta <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>d__1,dnorm<font face='Lucida Console'>)</font>;
                <b>}</b> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ratio <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> .<font color='#979000'>7</font><font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* Computing MAX */</font>
                    d__1 <font color='#5555FF'>=</font> half <font color='#5555FF'>*</font> delta;
                    delta <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__1,dnorm<font face='Lucida Console'>)</font>;
                <b>}</b> <font color='#0000FF'>else</font> <b>{</b>
                    <font color='#009900'>/* Computing MAX */</font>
                    d__1 <font color='#5555FF'>=</font> half <font color='#5555FF'>*</font> delta, d__2 <font color='#5555FF'>=</font> dnorm <font color='#5555FF'>+</font> dnorm;
                    delta <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>delta <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> rho <font color='#5555FF'>*</font> <font color='#979000'>1.5</font><font face='Lucida Console'>)</font> <b>{</b>
                    delta <font color='#5555FF'>=</font> rho;
                <b>}</b>

                <font color='#009900'>/*     Recalculate KNEW and DENOM if the new F is less than FOPT. */</font>

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>f <font color='#5555FF'>&lt;</font> fopt<font face='Lucida Console'>)</font> <b>{</b>
                    ksav <font color='#5555FF'>=</font> knew;
                    densav <font color='#5555FF'>=</font> denom;
                    delsq <font color='#5555FF'>=</font> delta <font color='#5555FF'>*</font> delta;
                    scaden <font color='#5555FF'>=</font> zero;
                    biglsq <font color='#5555FF'>=</font> zero;
                    knew <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                    i__1 <font color='#5555FF'>=</font> npt;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                        hdiag <font color='#5555FF'>=</font> zero;
                        i__2 <font color='#5555FF'>=</font> nptm;
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>jj <font color='#5555FF'>=</font> <font color='#979000'>1</font>; jj <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>jj<font face='Lucida Console'>)</font> <b>{</b>
                            <font color='#009900'>/* L440: */</font>
                            <font color='#009900'>/* Computing 2nd power */</font>
                            d__1 <font color='#5555FF'>=</font> zmat[k <font color='#5555FF'>+</font> jj <font color='#5555FF'>*</font> zmat_dim1];
                            hdiag <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                        <b>}</b>
                        <font color='#009900'>/* Computing 2nd power */</font>
                        d__1 <font color='#5555FF'>=</font> vlag[k];
                        den <font color='#5555FF'>=</font> beta <font color='#5555FF'>*</font> hdiag <font color='#5555FF'>+</font> d__1 <font color='#5555FF'>*</font> d__1;
                        distsq <font color='#5555FF'>=</font> zero;
                        i__2 <font color='#5555FF'>=</font> n;
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                            <font color='#009900'>/* L450: */</font>
                            <font color='#009900'>/* Computing 2nd power */</font>
                            d__1 <font color='#5555FF'>=</font> xpt[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>-</font> xnew[j];
                            distsq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                        <b>}</b>
                        <font color='#009900'>/* Computing MAX */</font>
                        <font color='#009900'>/* Computing 2nd power */</font>
                        d__3 <font color='#5555FF'>=</font> distsq <font color='#5555FF'>/</font> delsq;
                        d__1 <font color='#5555FF'>=</font> one, d__2 <font color='#5555FF'>=</font> d__3 <font color='#5555FF'>*</font> d__3;
                        temp <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp <font color='#5555FF'>*</font> den <font color='#5555FF'>&gt;</font> scaden<font face='Lucida Console'>)</font> <b>{</b>
                            scaden <font color='#5555FF'>=</font> temp <font color='#5555FF'>*</font> den;
                            knew <font color='#5555FF'>=</font> k;
                            denom <font color='#5555FF'>=</font> den;
                        <b>}</b>
                        <font color='#009900'>/* L460: */</font>
                        <font color='#009900'>/* Computing MAX */</font>
                        <font color='#009900'>/* Computing 2nd power */</font>
                        d__3 <font color='#5555FF'>=</font> vlag[k];
                        d__1 <font color='#5555FF'>=</font> biglsq, d__2 <font color='#5555FF'>=</font> temp <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>d__3 <font color='#5555FF'>*</font> d__3<font face='Lucida Console'>)</font>;
                        biglsq <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
                    <b>}</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>scaden <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> half <font color='#5555FF'>*</font> biglsq<font face='Lucida Console'>)</font> <b>{</b>
                        knew <font color='#5555FF'>=</font> ksav;
                        denom <font color='#5555FF'>=</font> densav;
                    <b>}</b>
                <b>}</b>
            <b>}</b>

            <font color='#009900'>/*     Update BMAT and ZMAT, so that the KNEW-th interpolation point can be */</font>
            <font color='#009900'>/*     moved. Also update the second derivative terms of the model. */</font>

            <font color='#BB00BB'>update_</font><font face='Lucida Console'>(</font>n, npt, <font color='#5555FF'>&amp;</font>bmat[bmat_offset], <font color='#5555FF'>&amp;</font>zmat[zmat_offset], ndim, <font color='#5555FF'>&amp;</font>vlag[<font color='#979000'>1</font>], 
                    beta, denom, knew, <font color='#5555FF'>&amp;</font>w[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font>;
            ih <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            pqold <font color='#5555FF'>=</font> pq[knew];
            pq[knew] <font color='#5555FF'>=</font> zero;
            i__1 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                temp <font color='#5555FF'>=</font> pqold <font color='#5555FF'>*</font> xpt[knew <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> xpt_dim1];
                i__2 <font color='#5555FF'>=</font> i__;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#5555FF'>+</font><font color='#5555FF'>+</font>ih;
                    <font color='#009900'>/* L470: */</font>
                    hq[ih] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp <font color='#5555FF'>*</font> xpt[knew <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1];
                <b>}</b>
            <b>}</b>
            i__2 <font color='#5555FF'>=</font> nptm;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>jj <font color='#5555FF'>=</font> <font color='#979000'>1</font>; jj <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>jj<font face='Lucida Console'>)</font> <b>{</b>
                temp <font color='#5555FF'>=</font> diff <font color='#5555FF'>*</font> zmat[knew <font color='#5555FF'>+</font> jj <font color='#5555FF'>*</font> zmat_dim1];
                i__1 <font color='#5555FF'>=</font> npt;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L480: */</font>
                    pq[k] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp <font color='#5555FF'>*</font> zmat[k <font color='#5555FF'>+</font> jj <font color='#5555FF'>*</font> zmat_dim1];
                <b>}</b>
            <b>}</b>

            <font color='#009900'>/*     Include the new interpolation point, and make the changes to GOPT at */</font>
            <font color='#009900'>/*     the old XOPT that are caused by the updating of the quadratic model. */</font>

            fval[knew] <font color='#5555FF'>=</font> f;
            i__1 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                xpt[knew <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>=</font> xnew[i__];
                <font color='#009900'>/* L490: */</font>
                w[i__] <font color='#5555FF'>=</font> bmat[knew <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> bmat_dim1];
            <b>}</b>
            i__1 <font color='#5555FF'>=</font> npt;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                suma <font color='#5555FF'>=</font> zero;
                i__2 <font color='#5555FF'>=</font> nptm;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>jj <font color='#5555FF'>=</font> <font color='#979000'>1</font>; jj <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>jj<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L500: */</font>
                    suma <font color='#5555FF'>+</font><font color='#5555FF'>=</font> zmat[knew <font color='#5555FF'>+</font> jj <font color='#5555FF'>*</font> zmat_dim1] <font color='#5555FF'>*</font> zmat[k <font color='#5555FF'>+</font> jj <font color='#5555FF'>*</font> zmat_dim1];
                <b>}</b>
                sumb <font color='#5555FF'>=</font> zero;
                i__2 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L510: */</font>
                    sumb <font color='#5555FF'>+</font><font color='#5555FF'>=</font> xpt[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>*</font> xopt[j];
                <b>}</b>
                temp <font color='#5555FF'>=</font> suma <font color='#5555FF'>*</font> sumb;
                i__2 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L520: */</font>
                    w[i__] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp <font color='#5555FF'>*</font> xpt[k <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> xpt_dim1];
                <b>}</b>
            <b>}</b>
            i__2 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#009900'>/* L530: */</font>
                gopt[i__] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> diff <font color='#5555FF'>*</font> w[i__];
            <b>}</b>

            <font color='#009900'>/*     Update XOPT, GOPT and KOPT if the new calculated F is less than FOPT. */</font>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>f <font color='#5555FF'>&lt;</font> fopt<font face='Lucida Console'>)</font> <b>{</b>
                kopt <font color='#5555FF'>=</font> knew;
                xoptsq <font color='#5555FF'>=</font> zero;
                ih <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                i__2 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                    xopt[j] <font color='#5555FF'>=</font> xnew[j];
                    <font color='#009900'>/* Computing 2nd power */</font>
                    d__1 <font color='#5555FF'>=</font> xopt[j];
                    xoptsq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                    i__1 <font color='#5555FF'>=</font> j;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#5555FF'>+</font><font color='#5555FF'>+</font>ih;
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>&lt;</font> j<font face='Lucida Console'>)</font> <b>{</b>
                            gopt[j] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> hq[ih] <font color='#5555FF'>*</font> d__[i__];
                        <b>}</b>
                        <font color='#009900'>/* L540: */</font>
                        gopt[i__] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> hq[ih] <font color='#5555FF'>*</font> d__[j];
                    <b>}</b>
                <b>}</b>
                i__1 <font color='#5555FF'>=</font> npt;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                    temp <font color='#5555FF'>=</font> zero;
                    i__2 <font color='#5555FF'>=</font> n;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#009900'>/* L550: */</font>
                        temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> xpt[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>*</font> d__[j];
                    <b>}</b>
                    temp <font color='#5555FF'>=</font> pq[k] <font color='#5555FF'>*</font> temp;
                    i__2 <font color='#5555FF'>=</font> n;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#009900'>/* L560: */</font>
                        gopt[i__] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp <font color='#5555FF'>*</font> xpt[k <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> xpt_dim1];
                    <b>}</b>
                <b>}</b>
            <b>}</b>

            <font color='#009900'>/*     Calculate the parameters of the least Frobenius norm interpolant to */</font>
            <font color='#009900'>/*     the current data, the gradient of this interpolant at XOPT being put */</font>
            <font color='#009900'>/*     into VLAG(NPT+I), I=1,2,...,N. */</font>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ntrits <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                i__2 <font color='#5555FF'>=</font> npt;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                    vlag[k] <font color='#5555FF'>=</font> fval[k] <font color='#5555FF'>-</font> fval[kopt];
                    <font color='#009900'>/* L570: */</font>
                    w[k] <font color='#5555FF'>=</font> zero;
                <b>}</b>
                i__2 <font color='#5555FF'>=</font> nptm;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                    sum <font color='#5555FF'>=</font> zero;
                    i__1 <font color='#5555FF'>=</font> npt;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#009900'>/* L580: */</font>
                        sum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> zmat[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1] <font color='#5555FF'>*</font> vlag[k];
                    <b>}</b>
                    i__1 <font color='#5555FF'>=</font> npt;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#009900'>/* L590: */</font>
                        w[k] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> sum <font color='#5555FF'>*</font> zmat[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1];
                    <b>}</b>
                <b>}</b>
                i__1 <font color='#5555FF'>=</font> npt;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                    sum <font color='#5555FF'>=</font> zero;
                    i__2 <font color='#5555FF'>=</font> n;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#009900'>/* L600: */</font>
                        sum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> xpt[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>*</font> xopt[j];
                    <b>}</b>
                    w[k <font color='#5555FF'>+</font> npt] <font color='#5555FF'>=</font> w[k];
                    <font color='#009900'>/* L610: */</font>
                    w[k] <font color='#5555FF'>=</font> sum <font color='#5555FF'>*</font> w[k];
                <b>}</b>
                gqsq <font color='#5555FF'>=</font> zero;
                gisq <font color='#5555FF'>=</font> zero;
                i__1 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                    sum <font color='#5555FF'>=</font> zero;
                    i__2 <font color='#5555FF'>=</font> npt;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#009900'>/* L620: */</font>
                        sum <font color='#5555FF'>=</font> sum <font color='#5555FF'>+</font> bmat[k <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>*</font> vlag[k] <font color='#5555FF'>+</font> xpt[k <font color='#5555FF'>+</font> i__ 
                            <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>*</font> w[k];
                    <b>}</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xopt[i__] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> sl[i__]<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#009900'>/* Computing MIN */</font>
                        d__2 <font color='#5555FF'>=</font> zero, d__3 <font color='#5555FF'>=</font> gopt[i__];
                        <font color='#009900'>/* Computing 2nd power */</font>
                        d__1 <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>d__2,d__3<font face='Lucida Console'>)</font>;
                        gqsq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                        <font color='#009900'>/* Computing 2nd power */</font>
                        d__1 <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>zero,sum<font face='Lucida Console'>)</font>;
                        gisq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                    <b>}</b> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xopt[i__] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> su[i__]<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#009900'>/* Computing MAX */</font>
                        d__2 <font color='#5555FF'>=</font> zero, d__3 <font color='#5555FF'>=</font> gopt[i__];
                        <font color='#009900'>/* Computing 2nd power */</font>
                        d__1 <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__2,d__3<font face='Lucida Console'>)</font>;
                        gqsq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                        <font color='#009900'>/* Computing 2nd power */</font>
                        d__1 <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>zero,sum<font face='Lucida Console'>)</font>;
                        gisq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                    <b>}</b> <font color='#0000FF'>else</font> <b>{</b>
                        <font color='#009900'>/* Computing 2nd power */</font>
                        d__1 <font color='#5555FF'>=</font> gopt[i__];
                        gqsq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                        gisq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> sum <font color='#5555FF'>*</font> sum;
                    <b>}</b>
                    <font color='#009900'>/* L630: */</font>
                    vlag[npt <font color='#5555FF'>+</font> i__] <font color='#5555FF'>=</font> sum;
                <b>}</b>

                <font color='#009900'>/*     Test whether to replace the new quadratic model by the least Frobenius */</font>
                <font color='#009900'>/*     norm interpolant, making the replacement if the test is satisfied. */</font>

                <font color='#5555FF'>+</font><font color='#5555FF'>+</font>itest;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>gqsq <font color='#5555FF'>&lt;</font> ten <font color='#5555FF'>*</font> gisq<font face='Lucida Console'>)</font> <b>{</b>
                    itest <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                <b>}</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>itest <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> <font color='#979000'>3</font><font face='Lucida Console'>)</font> <b>{</b>
                    i__1 <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>npt,nh<font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> n<font face='Lucida Console'>)</font> <b>{</b>
                            gopt[i__] <font color='#5555FF'>=</font> vlag[npt <font color='#5555FF'>+</font> i__];
                        <b>}</b>
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> npt<font face='Lucida Console'>)</font> <b>{</b>
                            pq[i__] <font color='#5555FF'>=</font> w[npt <font color='#5555FF'>+</font> i__];
                        <b>}</b>
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> nh<font face='Lucida Console'>)</font> <b>{</b>
                            hq[i__] <font color='#5555FF'>=</font> zero;
                        <b>}</b>
                        itest <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                        <font color='#009900'>/* L640: */</font>
                    <b>}</b>
                <b>}</b>
            <b>}</b>

            <font color='#009900'>/*     If a trust region step has provided a sufficient decrease in F, then */</font>
            <font color='#009900'>/*     branch for another trust region calculation. The case NTRITS=0 occurs */</font>
            <font color='#009900'>/*     when the new interpolation point was reached by an alternative step. */</font>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ntrits <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>goto</font> L60;
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>f <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> fopt <font color='#5555FF'>+</font> tenth <font color='#5555FF'>*</font> vquad<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>goto</font> L60;
            <b>}</b>

            <font color='#009900'>/*     Alternatively, find out if the interpolation points are close enough */</font>
            <font color='#009900'>/*       to the best point so far. */</font>

            <font color='#009900'>/* Computing MAX */</font>
            <font color='#009900'>/* Computing 2nd power */</font>
            d__3 <font color='#5555FF'>=</font> two <font color='#5555FF'>*</font> delta;
            <font color='#009900'>/* Computing 2nd power */</font>
            d__4 <font color='#5555FF'>=</font> ten <font color='#5555FF'>*</font> rho;
            d__1 <font color='#5555FF'>=</font> d__3 <font color='#5555FF'>*</font> d__3, d__2 <font color='#5555FF'>=</font> d__4 <font color='#5555FF'>*</font> d__4;
            distsq <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
L650:
            knew <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            i__1 <font color='#5555FF'>=</font> npt;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                sum <font color='#5555FF'>=</font> zero;
                i__2 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L660: */</font>
                    <font color='#009900'>/* Computing 2nd power */</font>
                    d__1 <font color='#5555FF'>=</font> xpt[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>-</font> xopt[j];
                    sum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                <b>}</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>sum <font color='#5555FF'>&gt;</font> distsq<font face='Lucida Console'>)</font> <b>{</b>
                    knew <font color='#5555FF'>=</font> k;
                    distsq <font color='#5555FF'>=</font> sum;
                <b>}</b>
                <font color='#009900'>/* L670: */</font>
            <b>}</b>

            <font color='#009900'>/*     If KNEW is positive, then ALTMOV finds alternative new positions for */</font>
            <font color='#009900'>/*     the KNEW-th interpolation point within distance ADELT of XOPT. It is */</font>
            <font color='#009900'>/*     reached via label 90. Otherwise, there is a branch to label 60 for */</font>
            <font color='#009900'>/*     another trust region iteration, unless the calculations with the */</font>
            <font color='#009900'>/*     current RHO are complete. */</font>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>knew <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                dist <font color='#5555FF'>=</font> std::<font color='#BB00BB'>sqrt</font><font face='Lucida Console'>(</font>distsq<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ntrits <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* Computing MIN */</font>
                    d__1 <font color='#5555FF'>=</font> tenth <font color='#5555FF'>*</font> delta, d__2 <font color='#5555FF'>=</font> half <font color='#5555FF'>*</font> dist;
                    delta <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>delta <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> rho <font color='#5555FF'>*</font> <font color='#979000'>1.5</font><font face='Lucida Console'>)</font> <b>{</b>
                        delta <font color='#5555FF'>=</font> rho;
                    <b>}</b>
                <b>}</b>
                ntrits <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                <font color='#009900'>/* Computing MAX */</font>
                <font color='#009900'>/* Computing MIN */</font>
                d__2 <font color='#5555FF'>=</font> tenth <font color='#5555FF'>*</font> dist;
                d__1 <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>d__2,delta<font face='Lucida Console'>)</font>;
                adelt <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__1,rho<font face='Lucida Console'>)</font>;
                dsq <font color='#5555FF'>=</font> adelt <font color='#5555FF'>*</font> adelt;
                <font color='#0000FF'>goto</font> L90;
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ntrits <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>goto</font> L680;
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ratio <font color='#5555FF'>&gt;</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>goto</font> L60;
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>delta,dnorm<font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> rho<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>goto</font> L60;
            <b>}</b>

            <font color='#009900'>/*     The calculations with the current value of RHO are complete. Pick the */</font>
            <font color='#009900'>/*       next values of RHO and DELTA. */</font>

L680:
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rho <font color='#5555FF'>&gt;</font> rhoend<font face='Lucida Console'>)</font> <b>{</b>
                delta <font color='#5555FF'>=</font> half <font color='#5555FF'>*</font> rho;
                ratio <font color='#5555FF'>=</font> rho <font color='#5555FF'>/</font> rhoend;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ratio <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> <font color='#979000'>16.</font><font face='Lucida Console'>)</font> <b>{</b>
                    rho <font color='#5555FF'>=</font> rhoend;
                <b>}</b> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ratio <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> <font color='#979000'>250.</font><font face='Lucida Console'>)</font> <b>{</b>
                    rho <font color='#5555FF'>=</font> std::<font color='#BB00BB'>sqrt</font><font face='Lucida Console'>(</font>ratio<font face='Lucida Console'>)</font> <font color='#5555FF'>*</font> rhoend;
                <b>}</b> <font color='#0000FF'>else</font> <b>{</b>
                    rho <font color='#5555FF'>=</font> tenth <font color='#5555FF'>*</font> rho;
                <b>}</b>
                delta <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>delta,rho<font face='Lucida Console'>)</font>;
                ntrits <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                nfsav <font color='#5555FF'>=</font> nf;
                <font color='#0000FF'>goto</font> L60;
            <b>}</b>

            <font color='#009900'>/*     Return from the calculation, after another Newton-Raphson step, if */</font>
            <font color='#009900'>/*       it is too short to have been tried before. */</font>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ntrits <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>goto</font> L360;
            <b>}</b>
L720:
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>fval[kopt] <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> fsave<font face='Lucida Console'>)</font> <b>{</b>
                i__1 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* Computing MIN */</font>
                    <font color='#009900'>/* Computing MAX */</font>
                    d__3 <font color='#5555FF'>=</font> xl[i__], d__4 <font color='#5555FF'>=</font> xbase[i__] <font color='#5555FF'>+</font> xopt[i__];
                    d__1 <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__3,d__4<font face='Lucida Console'>)</font>, d__2 <font color='#5555FF'>=</font> xu[i__];
                    x[i__] <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xopt[i__] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> sl[i__]<font face='Lucida Console'>)</font> <b>{</b>
                        x[i__] <font color='#5555FF'>=</font> xl[i__];
                    <b>}</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xopt[i__] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> su[i__]<font face='Lucida Console'>)</font> <b>{</b>
                        x[i__] <font color='#5555FF'>=</font> xu[i__];
                    <b>}</b>
                    <font color='#009900'>/* L730: */</font>
                <b>}</b>
                f <font color='#5555FF'>=</font> fval[kopt];
            <b>}</b>

            <font color='#0000FF'>return</font> f;
        <b>}</b> <font color='#009900'>/* bobyqb_ */</font>

    <font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='altmov_'></a>altmov_</b><font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> integer n,
            <font color='#0000FF'>const</font> integer npt,
            <font color='#0000FF'>const</font> doublereal <font color='#5555FF'>*</font>xpt, 
            <font color='#0000FF'>const</font> doublereal <font color='#5555FF'>*</font>xopt,
            <font color='#0000FF'>const</font> doublereal <font color='#5555FF'>*</font>bmat,
            <font color='#0000FF'>const</font> doublereal <font color='#5555FF'>*</font>zmat,
            <font color='#0000FF'>const</font> integer ndim, 
            <font color='#0000FF'>const</font> doublereal <font color='#5555FF'>*</font>sl,
            <font color='#0000FF'>const</font> doublereal <font color='#5555FF'>*</font>su,
            <font color='#0000FF'>const</font> integer kopt,
            <font color='#0000FF'>const</font> integer knew, 
            <font color='#0000FF'>const</font> doublereal adelt,
            doublereal <font color='#5555FF'>*</font>xnew,
            doublereal <font color='#5555FF'>*</font>xalt,
            doublereal<font color='#5555FF'>&amp;</font> alpha,
            doublereal<font color='#5555FF'>&amp;</font> cauchy,
            doublereal <font color='#5555FF'>*</font>glag,
            doublereal <font color='#5555FF'>*</font>hcol, 
            doublereal <font color='#5555FF'>*</font>w
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            <font color='#009900'>/* System generated locals */</font>
            integer xpt_dim1, xpt_offset, bmat_dim1, bmat_offset, zmat_dim1, 
            zmat_offset, i__1, i__2;
            doublereal d__1, d__2, d__3, d__4;


            <font color='#009900'>/* Local variables */</font>
            integer i__, j, k;
            doublereal ha, gw, one, diff, half;
            integer ilbd, isbd;
            doublereal slbd;
            integer iubd;
            doublereal vlag, subd, temp;
            integer ksav <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            doublereal step <font color='#5555FF'>=</font> <font color='#979000'>0</font>, zero <font color='#5555FF'>=</font> <font color='#979000'>0</font>, curv <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            integer iflag;
            doublereal scale <font color='#5555FF'>=</font> <font color='#979000'>0</font>, csave <font color='#5555FF'>=</font> <font color='#979000'>0</font>, tempa <font color='#5555FF'>=</font> <font color='#979000'>0</font>, tempb <font color='#5555FF'>=</font> <font color='#979000'>0</font>, tempd <font color='#5555FF'>=</font> <font color='#979000'>0</font>, const__ <font color='#5555FF'>=</font> <font color='#979000'>0</font>, sumin <font color='#5555FF'>=</font> <font color='#979000'>0</font>, 
                       ggfree <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            integer ibdsav <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            doublereal dderiv <font color='#5555FF'>=</font> <font color='#979000'>0</font>, bigstp <font color='#5555FF'>=</font> <font color='#979000'>0</font>, predsq <font color='#5555FF'>=</font> <font color='#979000'>0</font>, presav <font color='#5555FF'>=</font> <font color='#979000'>0</font>, distsq <font color='#5555FF'>=</font> <font color='#979000'>0</font>, stpsav <font color='#5555FF'>=</font> <font color='#979000'>0</font>, wfixsq <font color='#5555FF'>=</font> <font color='#979000'>0</font>, wsqsav <font color='#5555FF'>=</font> <font color='#979000'>0</font>;


            <font color='#009900'>/*     The arguments N, NPT, XPT, XOPT, BMAT, ZMAT, NDIM, SL and SU all have */</font>
            <font color='#009900'>/*       the same meanings as the corresponding arguments of BOBYQB. */</font>
            <font color='#009900'>/*     KOPT is the index of the optimal interpolation point. */</font>
            <font color='#009900'>/*     KNEW is the index of the interpolation point that is going to be moved. */</font>
            <font color='#009900'>/*     ADELT is the current trust region bound. */</font>
            <font color='#009900'>/*     XNEW will be set to a suitable new position for the interpolation point */</font>
            <font color='#009900'>/*       XPT(KNEW,.). Specifically, it satisfies the SL, SU and trust region */</font>
            <font color='#009900'>/*       bounds and it should provide a large denominator in the next call of */</font>
            <font color='#009900'>/*       UPDATE. The step XNEW-XOPT from XOPT is restricted to moves along the */</font>
            <font color='#009900'>/*       straight lines through XOPT and another interpolation point. */</font>
            <font color='#009900'>/*     XALT also provides a large value of the modulus of the KNEW-th Lagrange */</font>
            <font color='#009900'>/*       function subject to the constraints that have been mentioned, its main */</font>
            <font color='#009900'>/*       difference from XNEW being that XALT-XOPT is a constrained version of */</font>
            <font color='#009900'>/*       the Cauchy step within the trust region. An exception is that XALT is */</font>
            <font color='#009900'>/*       not calculated if all components of GLAG (see below) are zero. */</font>
            <font color='#009900'>/*     ALPHA will be set to the KNEW-th diagonal element of the H matrix. */</font>
            <font color='#009900'>/*     CAUCHY will be set to the square of the KNEW-th Lagrange function at */</font>
            <font color='#009900'>/*       the step XALT-XOPT from XOPT for the vector XALT that is returned, */</font>
            <font color='#009900'>/*       except that CAUCHY is set to zero if XALT is not calculated. */</font>
            <font color='#009900'>/*     GLAG is a working space vector of length N for the gradient of the */</font>
            <font color='#009900'>/*       KNEW-th Lagrange function at XOPT. */</font>
            <font color='#009900'>/*     HCOL is a working space vector of length NPT for the second derivative */</font>
            <font color='#009900'>/*       coefficients of the KNEW-th Lagrange function. */</font>
            <font color='#009900'>/*     W is a working space vector of length 2N that is going to hold the */</font>
            <font color='#009900'>/*       constrained Cauchy step from XOPT of the Lagrange function, followed */</font>
            <font color='#009900'>/*       by the downhill version of XALT when the uphill step is calculated. */</font>

            <font color='#009900'>/*     Set the first NPT components of W to the leading elements of the */</font>
            <font color='#009900'>/*     KNEW-th column of the H matrix. */</font>

            <font color='#009900'>/* Parameter adjustments */</font>
            zmat_dim1 <font color='#5555FF'>=</font> npt;
            zmat_offset <font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>+</font> zmat_dim1;
            zmat <font color='#5555FF'>-</font><font color='#5555FF'>=</font> zmat_offset;
            xpt_dim1 <font color='#5555FF'>=</font> npt;
            xpt_offset <font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>+</font> xpt_dim1;
            xpt <font color='#5555FF'>-</font><font color='#5555FF'>=</font> xpt_offset;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>xopt;
            bmat_dim1 <font color='#5555FF'>=</font> ndim;
            bmat_offset <font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>+</font> bmat_dim1;
            bmat <font color='#5555FF'>-</font><font color='#5555FF'>=</font> bmat_offset;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>sl;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>su;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>xnew;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>xalt;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>glag;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>hcol;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>w;

            <font color='#009900'>/* Function Body */</font>
            half <font color='#5555FF'>=</font> .<font color='#979000'>5</font>;
            one <font color='#5555FF'>=</font> <font color='#979000'>1.</font>;
            zero <font color='#5555FF'>=</font> <font color='#979000'>0.</font>;
            const__ <font color='#5555FF'>=</font> one <font color='#5555FF'>+</font> std::<font color='#BB00BB'>sqrt</font><font face='Lucida Console'>(</font><font color='#979000'>2.</font><font face='Lucida Console'>)</font>;
            i__1 <font color='#5555FF'>=</font> npt;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#009900'>/* L10: */</font>
                hcol[k] <font color='#5555FF'>=</font> zero;
            <b>}</b>
            i__1 <font color='#5555FF'>=</font> npt <font color='#5555FF'>-</font> n <font color='#5555FF'>-</font> <font color='#979000'>1</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                temp <font color='#5555FF'>=</font> zmat[knew <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1];
                i__2 <font color='#5555FF'>=</font> npt;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L20: */</font>
                    hcol[k] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp <font color='#5555FF'>*</font> zmat[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1];
                <b>}</b>
            <b>}</b>
            alpha <font color='#5555FF'>=</font> hcol[knew];
            ha <font color='#5555FF'>=</font> half <font color='#5555FF'>*</font> alpha;

            <font color='#009900'>/*     Calculate the gradient of the KNEW-th Lagrange function at XOPT. */</font>

            i__2 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#009900'>/* L30: */</font>
                glag[i__] <font color='#5555FF'>=</font> bmat[knew <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> bmat_dim1];
            <b>}</b>
            i__2 <font color='#5555FF'>=</font> npt;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                temp <font color='#5555FF'>=</font> zero;
                i__1 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L40: */</font>
                    temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> xpt[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>*</font> xopt[j];
                <b>}</b>
                temp <font color='#5555FF'>=</font> hcol[k] <font color='#5555FF'>*</font> temp;
                i__1 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L50: */</font>
                    glag[i__] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp <font color='#5555FF'>*</font> xpt[k <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> xpt_dim1];
                <b>}</b>
            <b>}</b>

            <font color='#009900'>/*     Search for a large denominator along the straight lines through XOPT */</font>
            <font color='#009900'>/*     and another interpolation point. SLBD and SUBD will be lower and upper */</font>
            <font color='#009900'>/*     bounds on the step along each of these lines in turn. PREDSQ will be */</font>
            <font color='#009900'>/*     set to the square of the predicted denominator for each line. PRESAV */</font>
            <font color='#009900'>/*     will be set to the largest admissible value of PREDSQ that occurs. */</font>

            presav <font color='#5555FF'>=</font> zero;
            i__1 <font color='#5555FF'>=</font> npt;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font><font color='#5555FF'>=</font> kopt<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#0000FF'>goto</font> L80;
                <b>}</b>
                dderiv <font color='#5555FF'>=</font> zero;
                distsq <font color='#5555FF'>=</font> zero;
                i__2 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                    temp <font color='#5555FF'>=</font> xpt[k <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>-</font> xopt[i__];
                    dderiv <font color='#5555FF'>+</font><font color='#5555FF'>=</font> glag[i__] <font color='#5555FF'>*</font> temp;
                    <font color='#009900'>/* L60: */</font>
                    distsq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp <font color='#5555FF'>*</font> temp;
                <b>}</b>
                subd <font color='#5555FF'>=</font> adelt <font color='#5555FF'>/</font> std::<font color='#BB00BB'>sqrt</font><font face='Lucida Console'>(</font>distsq<font face='Lucida Console'>)</font>;
                slbd <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>subd;
                ilbd <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                iubd <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                sumin <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>one,subd<font face='Lucida Console'>)</font>;

                <font color='#009900'>/*     Revise SLBD and SUBD if necessary because of the bounds in SL and SU. */</font>

                i__2 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                    temp <font color='#5555FF'>=</font> xpt[k <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>-</font> xopt[i__];
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp <font color='#5555FF'>&gt;</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>slbd <font color='#5555FF'>*</font> temp <font color='#5555FF'>&lt;</font> sl[i__] <font color='#5555FF'>-</font> xopt[i__]<font face='Lucida Console'>)</font> <b>{</b>
                            slbd <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>sl[i__] <font color='#5555FF'>-</font> xopt[i__]<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> temp;
                            ilbd <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>i__;
                        <b>}</b>
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>subd <font color='#5555FF'>*</font> temp <font color='#5555FF'>&gt;</font> su[i__] <font color='#5555FF'>-</font> xopt[i__]<font face='Lucida Console'>)</font> <b>{</b>
                            <font color='#009900'>/* Computing MAX */</font>
                            d__1 <font color='#5555FF'>=</font> sumin, d__2 <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>su[i__] <font color='#5555FF'>-</font> xopt[i__]<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> temp;
                            subd <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
                            iubd <font color='#5555FF'>=</font> i__;
                        <b>}</b>
                    <b>}</b> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp <font color='#5555FF'>&lt;</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>slbd <font color='#5555FF'>*</font> temp <font color='#5555FF'>&gt;</font> su[i__] <font color='#5555FF'>-</font> xopt[i__]<font face='Lucida Console'>)</font> <b>{</b>
                            slbd <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>su[i__] <font color='#5555FF'>-</font> xopt[i__]<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> temp;
                            ilbd <font color='#5555FF'>=</font> i__;
                        <b>}</b>
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>subd <font color='#5555FF'>*</font> temp <font color='#5555FF'>&lt;</font> sl[i__] <font color='#5555FF'>-</font> xopt[i__]<font face='Lucida Console'>)</font> <b>{</b>
                            <font color='#009900'>/* Computing MAX */</font>
                            d__1 <font color='#5555FF'>=</font> sumin, d__2 <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>sl[i__] <font color='#5555FF'>-</font> xopt[i__]<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> temp;
                            subd <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
                            iubd <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>i__;
                        <b>}</b>
                    <b>}</b>
                    <font color='#009900'>/* L70: */</font>
                <b>}</b>

                <font color='#009900'>/*     Seek a large modulus of the KNEW-th Lagrange function when the index */</font>
                <font color='#009900'>/*     of the other interpolation point on the line through XOPT is KNEW. */</font>

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font><font color='#5555FF'>=</font> knew<font face='Lucida Console'>)</font> <b>{</b>
                    diff <font color='#5555FF'>=</font> dderiv <font color='#5555FF'>-</font> one;
                    step <font color='#5555FF'>=</font> slbd;
                    vlag <font color='#5555FF'>=</font> slbd <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>dderiv <font color='#5555FF'>-</font> slbd <font color='#5555FF'>*</font> diff<font face='Lucida Console'>)</font>;
                    isbd <font color='#5555FF'>=</font> ilbd;
                    temp <font color='#5555FF'>=</font> subd <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>dderiv <font color='#5555FF'>-</font> subd <font color='#5555FF'>*</font> diff<font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>vlag<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <b>{</b>
                        step <font color='#5555FF'>=</font> subd;
                        vlag <font color='#5555FF'>=</font> temp;
                        isbd <font color='#5555FF'>=</font> iubd;
                    <b>}</b>
                    tempd <font color='#5555FF'>=</font> half <font color='#5555FF'>*</font> dderiv;
                    tempa <font color='#5555FF'>=</font> tempd <font color='#5555FF'>-</font> diff <font color='#5555FF'>*</font> slbd;
                    tempb <font color='#5555FF'>=</font> tempd <font color='#5555FF'>-</font> diff <font color='#5555FF'>*</font> subd;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>tempa <font color='#5555FF'>*</font> tempb <font color='#5555FF'>&lt;</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                        temp <font color='#5555FF'>=</font> tempd <font color='#5555FF'>*</font> tempd <font color='#5555FF'>/</font> diff;
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>vlag<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <b>{</b>
                            step <font color='#5555FF'>=</font> tempd <font color='#5555FF'>/</font> diff;
                            vlag <font color='#5555FF'>=</font> temp;
                            isbd <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                        <b>}</b>
                    <b>}</b>

                    <font color='#009900'>/*     Search along each of the other lines through XOPT and another point. */</font>

                <b>}</b> <font color='#0000FF'>else</font> <b>{</b>
                    step <font color='#5555FF'>=</font> slbd;
                    vlag <font color='#5555FF'>=</font> slbd <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>one <font color='#5555FF'>-</font> slbd<font face='Lucida Console'>)</font>;
                    isbd <font color='#5555FF'>=</font> ilbd;
                    temp <font color='#5555FF'>=</font> subd <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>one <font color='#5555FF'>-</font> subd<font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>vlag<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <b>{</b>
                        step <font color='#5555FF'>=</font> subd;
                        vlag <font color='#5555FF'>=</font> temp;
                        isbd <font color='#5555FF'>=</font> iubd;
                    <b>}</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>subd <font color='#5555FF'>&gt;</font> half<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>vlag<font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> .<font color='#979000'>25</font><font face='Lucida Console'>)</font> <b>{</b>
                            step <font color='#5555FF'>=</font> half;
                            vlag <font color='#5555FF'>=</font> .<font color='#979000'>25</font>;
                            isbd <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                        <b>}</b>
                    <b>}</b>
                    vlag <font color='#5555FF'>*</font><font color='#5555FF'>=</font> dderiv;
                <b>}</b>

                <font color='#009900'>/*     Calculate PREDSQ for the current line search and maintain PRESAV. */</font>

                temp <font color='#5555FF'>=</font> step <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>one <font color='#5555FF'>-</font> step<font face='Lucida Console'>)</font> <font color='#5555FF'>*</font> distsq;
                predsq <font color='#5555FF'>=</font> vlag <font color='#5555FF'>*</font> vlag <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>vlag <font color='#5555FF'>*</font> vlag <font color='#5555FF'>+</font> ha <font color='#5555FF'>*</font> temp <font color='#5555FF'>*</font> temp<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>predsq <font color='#5555FF'>&gt;</font> presav<font face='Lucida Console'>)</font> <b>{</b>
                    presav <font color='#5555FF'>=</font> predsq;
                    ksav <font color='#5555FF'>=</font> k;
                    stpsav <font color='#5555FF'>=</font> step;
                    ibdsav <font color='#5555FF'>=</font> isbd;
                <b>}</b>
L80:
                ;
            <b>}</b>

            <font color='#009900'>/*     Construct XNEW in a way that satisfies the bound constraints exactly. */</font>

            i__1 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                temp <font color='#5555FF'>=</font> xopt[i__] <font color='#5555FF'>+</font> stpsav <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>xpt[ksav <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>-</font> xopt[i__]<font face='Lucida Console'>)</font>;
                <font color='#009900'>/* L90: */</font>
                <font color='#009900'>/* Computing MAX */</font>
                <font color='#009900'>/* Computing MIN */</font>
                d__3 <font color='#5555FF'>=</font> su[i__];
                d__1 <font color='#5555FF'>=</font> sl[i__], d__2 <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>d__3,temp<font face='Lucida Console'>)</font>;
                xnew[i__] <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ibdsav <font color='#5555FF'>&lt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                xnew[<font color='#5555FF'>-</font>ibdsav] <font color='#5555FF'>=</font> sl[<font color='#5555FF'>-</font>ibdsav];
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ibdsav <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                xnew[ibdsav] <font color='#5555FF'>=</font> su[ibdsav];
            <b>}</b>

            <font color='#009900'>/*     Prepare for the iterative method that assembles the constrained Cauchy */</font>
            <font color='#009900'>/*     step in W. The sum of squares of the fixed components of W is formed in */</font>
            <font color='#009900'>/*     WFIXSQ, and the free components of W are set to BIGSTP. */</font>

            bigstp <font color='#5555FF'>=</font> adelt <font color='#5555FF'>+</font> adelt;
            iflag <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
L100:
            wfixsq <font color='#5555FF'>=</font> zero;
            ggfree <font color='#5555FF'>=</font> zero;
            i__1 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                w[i__] <font color='#5555FF'>=</font> zero;
                <font color='#009900'>/* Computing MIN */</font>
                d__1 <font color='#5555FF'>=</font> xopt[i__] <font color='#5555FF'>-</font> sl[i__], d__2 <font color='#5555FF'>=</font> glag[i__];
                tempa <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
                <font color='#009900'>/* Computing MAX */</font>
                d__1 <font color='#5555FF'>=</font> xopt[i__] <font color='#5555FF'>-</font> su[i__], d__2 <font color='#5555FF'>=</font> glag[i__];
                tempb <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>tempa <font color='#5555FF'>&gt;</font> zero <font color='#5555FF'>|</font><font color='#5555FF'>|</font> tempb <font color='#5555FF'>&lt;</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    w[i__] <font color='#5555FF'>=</font> bigstp;
                    <font color='#009900'>/* Computing 2nd power */</font>
                    d__1 <font color='#5555FF'>=</font> glag[i__];
                    ggfree <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                <b>}</b>
                <font color='#009900'>/* L110: */</font>
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ggfree <font color='#5555FF'>=</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                cauchy <font color='#5555FF'>=</font> zero;
                <font color='#0000FF'>goto</font> L200;
            <b>}</b>

            <font color='#009900'>/*     Investigate whether more components of W can be fixed. */</font>

L120:
            temp <font color='#5555FF'>=</font> adelt <font color='#5555FF'>*</font> adelt <font color='#5555FF'>-</font> wfixsq;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp <font color='#5555FF'>&gt;</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                wsqsav <font color='#5555FF'>=</font> wfixsq;
                step <font color='#5555FF'>=</font> std::<font color='#BB00BB'>sqrt</font><font face='Lucida Console'>(</font>temp <font color='#5555FF'>/</font> ggfree<font face='Lucida Console'>)</font>;
                ggfree <font color='#5555FF'>=</font> zero;
                i__1 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>w[i__] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> bigstp<font face='Lucida Console'>)</font> <b>{</b>
                        temp <font color='#5555FF'>=</font> xopt[i__] <font color='#5555FF'>-</font> step <font color='#5555FF'>*</font> glag[i__];
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> sl[i__]<font face='Lucida Console'>)</font> <b>{</b>
                            w[i__] <font color='#5555FF'>=</font> sl[i__] <font color='#5555FF'>-</font> xopt[i__];
                            <font color='#009900'>/* Computing 2nd power */</font>
                            d__1 <font color='#5555FF'>=</font> w[i__];
                            wfixsq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                        <b>}</b> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> su[i__]<font face='Lucida Console'>)</font> <b>{</b>
                            w[i__] <font color='#5555FF'>=</font> su[i__] <font color='#5555FF'>-</font> xopt[i__];
                            <font color='#009900'>/* Computing 2nd power */</font>
                            d__1 <font color='#5555FF'>=</font> w[i__];
                            wfixsq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                        <b>}</b> <font color='#0000FF'>else</font> <b>{</b>
                            <font color='#009900'>/* Computing 2nd power */</font>
                            d__1 <font color='#5555FF'>=</font> glag[i__];
                            ggfree <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                        <b>}</b>
                    <b>}</b>
                    <font color='#009900'>/* L130: */</font>
                <b>}</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>wfixsq <font color='#5555FF'>&gt;</font> wsqsav <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> ggfree <font color='#5555FF'>&gt;</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#0000FF'>goto</font> L120;
                <b>}</b>
            <b>}</b>

            <font color='#009900'>/*     Set the remaining free components of W and all components of XALT, */</font>
            <font color='#009900'>/*     except that W may be scaled later. */</font>

            gw <font color='#5555FF'>=</font> zero;
            i__1 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>w[i__] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> bigstp<font face='Lucida Console'>)</font> <b>{</b>
                    w[i__] <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>step <font color='#5555FF'>*</font> glag[i__];
                    <font color='#009900'>/* Computing MAX */</font>
                    <font color='#009900'>/* Computing MIN */</font>
                    d__3 <font color='#5555FF'>=</font> su[i__], d__4 <font color='#5555FF'>=</font> xopt[i__] <font color='#5555FF'>+</font> w[i__];
                    d__1 <font color='#5555FF'>=</font> sl[i__], d__2 <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>d__3,d__4<font face='Lucida Console'>)</font>;
                    xalt[i__] <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
                <b>}</b> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>w[i__] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    xalt[i__] <font color='#5555FF'>=</font> xopt[i__];
                <b>}</b> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>glag[i__] <font color='#5555FF'>&gt;</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    xalt[i__] <font color='#5555FF'>=</font> sl[i__];
                <b>}</b> <font color='#0000FF'>else</font> <b>{</b>
                    xalt[i__] <font color='#5555FF'>=</font> su[i__];
                <b>}</b>
                <font color='#009900'>/* L140: */</font>
                gw <font color='#5555FF'>+</font><font color='#5555FF'>=</font> glag[i__] <font color='#5555FF'>*</font> w[i__];
            <b>}</b>

            <font color='#009900'>/*     Set CURV to the curvature of the KNEW-th Lagrange function along W. */</font>
            <font color='#009900'>/*     Scale W by a factor less than one if that can reduce the modulus of */</font>
            <font color='#009900'>/*     the Lagrange function at XOPT+W. Set CAUCHY to the final value of */</font>
            <font color='#009900'>/*     the square of this function. */</font>

            curv <font color='#5555FF'>=</font> zero;
            i__1 <font color='#5555FF'>=</font> npt;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                temp <font color='#5555FF'>=</font> zero;
                i__2 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L150: */</font>
                    temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> xpt[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>*</font> w[j];
                <b>}</b>
                <font color='#009900'>/* L160: */</font>
                curv <font color='#5555FF'>+</font><font color='#5555FF'>=</font> hcol[k] <font color='#5555FF'>*</font> temp <font color='#5555FF'>*</font> temp;
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>iflag <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <b>{</b>
                curv <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>curv;
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>curv <font color='#5555FF'>&gt;</font> <font color='#5555FF'>-</font>gw <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> curv <font color='#5555FF'>&lt;</font> <font color='#5555FF'>-</font>const__ <font color='#5555FF'>*</font> gw<font face='Lucida Console'>)</font> <b>{</b>
                scale <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>gw <font color='#5555FF'>/</font> curv;
                i__1 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                    temp <font color='#5555FF'>=</font> xopt[i__] <font color='#5555FF'>+</font> scale <font color='#5555FF'>*</font> w[i__];
                    <font color='#009900'>/* L170: */</font>
                    <font color='#009900'>/* Computing MAX */</font>
                    <font color='#009900'>/* Computing MIN */</font>
                    d__3 <font color='#5555FF'>=</font> su[i__];
                    d__1 <font color='#5555FF'>=</font> sl[i__], d__2 <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>d__3,temp<font face='Lucida Console'>)</font>;
                    xalt[i__] <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#009900'>/* Computing 2nd power */</font>
                d__1 <font color='#5555FF'>=</font> half <font color='#5555FF'>*</font> gw <font color='#5555FF'>*</font> scale;
                cauchy <font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
            <b>}</b> <font color='#0000FF'>else</font> <b>{</b>
                <font color='#009900'>/* Computing 2nd power */</font>
                d__1 <font color='#5555FF'>=</font> gw <font color='#5555FF'>+</font> half <font color='#5555FF'>*</font> curv;
                cauchy <font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
            <b>}</b>

            <font color='#009900'>/*     If IFLAG is zero, then XALT is calculated as before after reversing */</font>
            <font color='#009900'>/*     the sign of GLAG. Thus two XALT vectors become available. The one that */</font>
            <font color='#009900'>/*     is chosen is the one that gives the larger value of CAUCHY. */</font>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>iflag <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                i__1 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                    glag[i__] <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>glag[i__];
                    <font color='#009900'>/* L180: */</font>
                    w[n <font color='#5555FF'>+</font> i__] <font color='#5555FF'>=</font> xalt[i__];
                <b>}</b>
                csave <font color='#5555FF'>=</font> cauchy;
                iflag <font color='#5555FF'>=</font> <font color='#979000'>1</font>;
                <font color='#0000FF'>goto</font> L100;
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>csave <font color='#5555FF'>&gt;</font> cauchy<font face='Lucida Console'>)</font> <b>{</b>
                i__1 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L190: */</font>
                    xalt[i__] <font color='#5555FF'>=</font> w[n <font color='#5555FF'>+</font> i__];
                <b>}</b>
                cauchy <font color='#5555FF'>=</font> csave;
            <b>}</b>
L200:
            ;
        <b>}</b> <font color='#009900'>/* altmov_ */</font>

    <font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> funct<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='prelim_'></a>prelim_</b><font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> funct<font color='#5555FF'>&amp;</font> calfun,
            <font color='#0000FF'>const</font> integer n,
            <font color='#0000FF'>const</font> integer npt,
            doublereal <font color='#5555FF'>*</font>x, 
            <font color='#0000FF'>const</font> doublereal <font color='#5555FF'>*</font>xl,
            <font color='#0000FF'>const</font> doublereal <font color='#5555FF'>*</font>xu,
            <font color='#0000FF'>const</font> doublereal rhobeg,
            <font color='#0000FF'>const</font> integer maxfun,
            doublereal <font color='#5555FF'>*</font>xbase,
            doublereal <font color='#5555FF'>*</font>xpt,
            doublereal <font color='#5555FF'>*</font>fval,
            doublereal <font color='#5555FF'>*</font>gopt,
            doublereal <font color='#5555FF'>*</font>hq,
            doublereal <font color='#5555FF'>*</font>pq,
            doublereal <font color='#5555FF'>*</font>bmat, 
            doublereal <font color='#5555FF'>*</font>zmat,
            <font color='#0000FF'>const</font> integer ndim,
            <font color='#0000FF'>const</font> doublereal <font color='#5555FF'>*</font>sl,
            <font color='#0000FF'>const</font> doublereal <font color='#5555FF'>*</font>su, 
            integer<font color='#5555FF'>&amp;</font> nf, 
            integer<font color='#5555FF'>&amp;</font> kopt
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            <font color='#009900'>/* System generated locals */</font>
            integer xpt_dim1, xpt_offset, bmat_dim1, bmat_offset, zmat_dim1, 
            zmat_offset, i__1, i__2;
            doublereal d__1, d__2, d__3, d__4;


            <font color='#009900'>/* Local variables */</font>
            doublereal f;
            integer i__, j, k, ih, np, nfm;
            doublereal one;
            integer nfx <font color='#5555FF'>=</font> <font color='#979000'>0</font>, ipt <font color='#5555FF'>=</font> <font color='#979000'>0</font>, jpt <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            doublereal two <font color='#5555FF'>=</font> <font color='#979000'>0</font>, fbeg <font color='#5555FF'>=</font> <font color='#979000'>0</font>, diff <font color='#5555FF'>=</font> <font color='#979000'>0</font>, half <font color='#5555FF'>=</font> <font color='#979000'>0</font>, temp <font color='#5555FF'>=</font> <font color='#979000'>0</font>, zero <font color='#5555FF'>=</font> <font color='#979000'>0</font>, recip <font color='#5555FF'>=</font> <font color='#979000'>0</font>, stepa <font color='#5555FF'>=</font> <font color='#979000'>0</font>, stepb <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            integer itemp;
            doublereal rhosq;



            <font color='#009900'>/*     The arguments N, NPT, X, XL, XU, RHOBEG, IPRINT and MAXFUN are the */</font>
            <font color='#009900'>/*       same as the corresponding arguments in SUBROUTINE BOBYQA. */</font>
            <font color='#009900'>/*     The arguments XBASE, XPT, FVAL, HQ, PQ, BMAT, ZMAT, NDIM, SL and SU */</font>
            <font color='#009900'>/*       are the same as the corresponding arguments in BOBYQB, the elements */</font>
            <font color='#009900'>/*       of SL and SU being set in BOBYQA. */</font>
            <font color='#009900'>/*     GOPT is usually the gradient of the quadratic model at XOPT+XBASE, but */</font>
            <font color='#009900'>/*       it is set by PRELIM to the gradient of the quadratic model at XBASE. */</font>
            <font color='#009900'>/*       If XOPT is nonzero, BOBYQB will change it to its usual value later. */</font>
            <font color='#009900'>/*     NF is maintaned as the number of calls of CALFUN so far. */</font>
            <font color='#009900'>/*     KOPT will be such that the least calculated value of F so far is at */</font>
            <font color='#009900'>/*       the point XPT(KOPT,.)+XBASE in the space of the variables. */</font>

            <font color='#009900'>/*     SUBROUTINE PRELIM sets the elements of XBASE, XPT, FVAL, GOPT, HQ, PQ, */</font>
            <font color='#009900'>/*     BMAT and ZMAT for the first iteration, and it maintains the values of */</font>
            <font color='#009900'>/*     NF and KOPT. The vector X is also changed by PRELIM. */</font>

            <font color='#009900'>/*     Set some constants. */</font>

            <font color='#009900'>/* Parameter adjustments */</font>
            zmat_dim1 <font color='#5555FF'>=</font> npt;
            zmat_offset <font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>+</font> zmat_dim1;
            zmat <font color='#5555FF'>-</font><font color='#5555FF'>=</font> zmat_offset;
            xpt_dim1 <font color='#5555FF'>=</font> npt;
            xpt_offset <font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>+</font> xpt_dim1;
            xpt <font color='#5555FF'>-</font><font color='#5555FF'>=</font> xpt_offset;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>x;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>xl;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>xu;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>xbase;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>fval;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>gopt;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>hq;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>pq;
            bmat_dim1 <font color='#5555FF'>=</font> ndim;
            bmat_offset <font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>+</font> bmat_dim1;
            bmat <font color='#5555FF'>-</font><font color='#5555FF'>=</font> bmat_offset;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>sl;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>su;

            <font color='#009900'>/* Function Body */</font>
            half <font color='#5555FF'>=</font> .<font color='#979000'>5</font>;
            one <font color='#5555FF'>=</font> <font color='#979000'>1.</font>;
            two <font color='#5555FF'>=</font> <font color='#979000'>2.</font>;
            zero <font color='#5555FF'>=</font> <font color='#979000'>0.</font>;
            rhosq <font color='#5555FF'>=</font> rhobeg <font color='#5555FF'>*</font> rhobeg;
            recip <font color='#5555FF'>=</font> one <font color='#5555FF'>/</font> rhosq;
            np <font color='#5555FF'>=</font> n <font color='#5555FF'>+</font> <font color='#979000'>1</font>;

            <font color='#009900'>/*     Set XBASE to the initial vector of variables, and set the initial */</font>
            <font color='#009900'>/*     elements of XPT, BMAT, HQ, PQ and ZMAT to zero. */</font>

            i__1 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                xbase[j] <font color='#5555FF'>=</font> x[j];
                i__2 <font color='#5555FF'>=</font> npt;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L10: */</font>
                    xpt[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>=</font> zero;
                <b>}</b>
                i__2 <font color='#5555FF'>=</font> ndim;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L20: */</font>
                    bmat[i__ <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>=</font> zero;
                <b>}</b>
            <b>}</b>
            i__2 <font color='#5555FF'>=</font> n <font color='#5555FF'>*</font> np <font color='#5555FF'>/</font> <font color='#979000'>2</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>ih <font color='#5555FF'>=</font> <font color='#979000'>1</font>; ih <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>ih<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#009900'>/* L30: */</font>
                hq[ih] <font color='#5555FF'>=</font> zero;
            <b>}</b>
            i__2 <font color='#5555FF'>=</font> npt;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                pq[k] <font color='#5555FF'>=</font> zero;
                i__1 <font color='#5555FF'>=</font> npt <font color='#5555FF'>-</font> np;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L40: */</font>
                    zmat[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1] <font color='#5555FF'>=</font> zero;
                <b>}</b>
            <b>}</b>

            <font color='#009900'>/*     Begin the initialization procedure. NF becomes one more than the number */</font>
            <font color='#009900'>/*     of function values so far. The coordinates of the displacement of the */</font>
            <font color='#009900'>/*     next initial interpolation point from XBASE are set in XPT(NF+1,.). */</font>

            nf <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
L50:
            nfm <font color='#5555FF'>=</font> nf;
            nfx <font color='#5555FF'>=</font> nf <font color='#5555FF'>-</font> n;
            <font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>(</font>nf<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>nfm <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> n <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>nfm <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> nfm <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> n<font face='Lucida Console'>)</font> <b>{</b>
                    stepa <font color='#5555FF'>=</font> rhobeg;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>su[nfm] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                        stepa <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>stepa;
                    <b>}</b>
                    xpt[nf <font color='#5555FF'>+</font> nfm <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>=</font> stepa;
                <b>}</b> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>nfm <font color='#5555FF'>&gt;</font> n<font face='Lucida Console'>)</font> <b>{</b>
                    stepa <font color='#5555FF'>=</font> xpt[nf <font color='#5555FF'>-</font> n <font color='#5555FF'>+</font> nfx <font color='#5555FF'>*</font> xpt_dim1];
                    stepb <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font face='Lucida Console'>(</font>rhobeg<font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>sl[nfx] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#009900'>/* Computing MIN */</font>
                        d__1 <font color='#5555FF'>=</font> two <font color='#5555FF'>*</font> rhobeg, d__2 <font color='#5555FF'>=</font> su[nfx];
                        stepb <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
                    <b>}</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>su[nfx] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#009900'>/* Computing MAX */</font>
                        d__1 <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>two <font color='#5555FF'>*</font> rhobeg, d__2 <font color='#5555FF'>=</font> sl[nfx];
                        stepb <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
                    <b>}</b>
                    xpt[nf <font color='#5555FF'>+</font> nfx <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>=</font> stepb;
                <b>}</b>
            <b>}</b> <font color='#0000FF'>else</font> <b>{</b>
                itemp <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>nfm <font color='#5555FF'>-</font> np<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> n;
                jpt <font color='#5555FF'>=</font> nfm <font color='#5555FF'>-</font> itemp <font color='#5555FF'>*</font> n <font color='#5555FF'>-</font> n;
                ipt <font color='#5555FF'>=</font> jpt <font color='#5555FF'>+</font> itemp;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ipt <font color='#5555FF'>&gt;</font> n<font face='Lucida Console'>)</font> <b>{</b>
                    itemp <font color='#5555FF'>=</font> jpt;
                    jpt <font color='#5555FF'>=</font> ipt <font color='#5555FF'>-</font> n;
                    ipt <font color='#5555FF'>=</font> itemp;
                <b>}</b>
                xpt[nf <font color='#5555FF'>+</font> ipt <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>=</font> xpt[ipt <font color='#5555FF'>+</font> <font color='#979000'>1</font> <font color='#5555FF'>+</font> ipt <font color='#5555FF'>*</font> xpt_dim1];
                xpt[nf <font color='#5555FF'>+</font> jpt <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>=</font> xpt[jpt <font color='#5555FF'>+</font> <font color='#979000'>1</font> <font color='#5555FF'>+</font> jpt <font color='#5555FF'>*</font> xpt_dim1];
            <b>}</b>

            <font color='#009900'>/*     Calculate the next value of F. The least function value so far and */</font>
            <font color='#009900'>/*     its index are required. */</font>

            i__1 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#009900'>/* Computing MIN */</font>
                <font color='#009900'>/* Computing MAX */</font>
                d__3 <font color='#5555FF'>=</font> xl[j], d__4 <font color='#5555FF'>=</font> xbase[j] <font color='#5555FF'>+</font> xpt[nf <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1];
                d__1 <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__3,d__4<font face='Lucida Console'>)</font>, d__2 <font color='#5555FF'>=</font> xu[j];
                x[j] <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xpt[nf <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> sl[j]<font face='Lucida Console'>)</font> <b>{</b>
                    x[j] <font color='#5555FF'>=</font> xl[j];
                <b>}</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xpt[nf <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> su[j]<font face='Lucida Console'>)</font> <b>{</b>
                    x[j] <font color='#5555FF'>=</font> xu[j];
                <b>}</b>
                <font color='#009900'>/* L60: */</font>
            <b>}</b>
            f <font color='#5555FF'>=</font> <font color='#BB00BB'>calfun</font><font face='Lucida Console'>(</font><font color='#BB00BB'>mat</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>x[<font color='#979000'>1</font>],n<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            fval[nf] <font color='#5555FF'>=</font> f;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>nf <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <b>{</b>
                fbeg <font color='#5555FF'>=</font> f;
                kopt <font color='#5555FF'>=</font> <font color='#979000'>1</font>;
            <b>}</b> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>f <font color='#5555FF'>&lt;</font> fval[kopt]<font face='Lucida Console'>)</font> <b>{</b>
                kopt <font color='#5555FF'>=</font> nf;
            <b>}</b>

            <font color='#009900'>/*     Set the nonzero initial elements of BMAT and the quadratic model in the */</font>
            <font color='#009900'>/*     cases when NF is at most 2*N+1. If NF exceeds N+1, then the positions */</font>
            <font color='#009900'>/*     of the NF-th and (NF-N)-th interpolation points may be switched, in */</font>
            <font color='#009900'>/*     order that the function value at the first of them contributes to the */</font>
            <font color='#009900'>/*     off-diagonal second derivative terms of the initial quadratic model. */</font>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>nf <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>n <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>nf <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> <font color='#979000'>2</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> nf <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> n <font color='#5555FF'>+</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <b>{</b>
                    gopt[nfm] <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>f <font color='#5555FF'>-</font> fbeg<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> stepa;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>npt <font color='#5555FF'>&lt;</font> nf <font color='#5555FF'>+</font> n<font face='Lucida Console'>)</font> <b>{</b>
                        bmat[nfm <font color='#5555FF'>*</font> bmat_dim1 <font color='#5555FF'>+</font> <font color='#979000'>1</font>] <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>one <font color='#5555FF'>/</font> stepa;
                        bmat[nf <font color='#5555FF'>+</font> nfm <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>=</font> one <font color='#5555FF'>/</font> stepa;
                        bmat[npt <font color='#5555FF'>+</font> nfm <font color='#5555FF'>+</font> nfm <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>half <font color='#5555FF'>*</font> rhosq;
                    <b>}</b>
                <b>}</b> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>nf <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> n <font color='#5555FF'>+</font> <font color='#979000'>2</font><font face='Lucida Console'>)</font> <b>{</b>
                    ih <font color='#5555FF'>=</font> nfx <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>nfx <font color='#5555FF'>+</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> <font color='#979000'>2</font>;
                    temp <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>f <font color='#5555FF'>-</font> fbeg<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> stepb;
                    diff <font color='#5555FF'>=</font> stepb <font color='#5555FF'>-</font> stepa;
                    hq[ih] <font color='#5555FF'>=</font> two <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>temp <font color='#5555FF'>-</font> gopt[nfx]<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> diff;
                    gopt[nfx] <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>gopt[nfx] <font color='#5555FF'>*</font> stepb <font color='#5555FF'>-</font> temp <font color='#5555FF'>*</font> stepa<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> diff;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>stepa <font color='#5555FF'>*</font> stepb <font color='#5555FF'>&lt;</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>f <font color='#5555FF'>&lt;</font> fval[nf <font color='#5555FF'>-</font> n]<font face='Lucida Console'>)</font> <b>{</b>
                            fval[nf] <font color='#5555FF'>=</font> fval[nf <font color='#5555FF'>-</font> n];
                            fval[nf <font color='#5555FF'>-</font> n] <font color='#5555FF'>=</font> f;
                            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>kopt <font color='#5555FF'>=</font><font color='#5555FF'>=</font> nf<font face='Lucida Console'>)</font> <b>{</b>
                                kopt <font color='#5555FF'>=</font> nf <font color='#5555FF'>-</font> n;
                            <b>}</b>
                            xpt[nf <font color='#5555FF'>-</font> n <font color='#5555FF'>+</font> nfx <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>=</font> stepb;
                            xpt[nf <font color='#5555FF'>+</font> nfx <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>=</font> stepa;
                        <b>}</b>
                    <b>}</b>
                    bmat[nfx <font color='#5555FF'>*</font> bmat_dim1 <font color='#5555FF'>+</font> <font color='#979000'>1</font>] <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font face='Lucida Console'>(</font>stepa <font color='#5555FF'>+</font> stepb<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> <font face='Lucida Console'>(</font>stepa <font color='#5555FF'>*</font> stepb<font face='Lucida Console'>)</font>;
                    bmat[nf <font color='#5555FF'>+</font> nfx <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>half <font color='#5555FF'>/</font> xpt[nf <font color='#5555FF'>-</font> n <font color='#5555FF'>+</font> nfx <font color='#5555FF'>*</font> 
                        xpt_dim1];
                    bmat[nf <font color='#5555FF'>-</font> n <font color='#5555FF'>+</font> nfx <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>bmat[nfx <font color='#5555FF'>*</font> bmat_dim1 <font color='#5555FF'>+</font> <font color='#979000'>1</font>] <font color='#5555FF'>-</font> 
                        bmat[nf <font color='#5555FF'>+</font> nfx <font color='#5555FF'>*</font> bmat_dim1];
                    zmat[nfx <font color='#5555FF'>*</font> zmat_dim1 <font color='#5555FF'>+</font> <font color='#979000'>1</font>] <font color='#5555FF'>=</font> std::<font color='#BB00BB'>sqrt</font><font face='Lucida Console'>(</font>two<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> <font face='Lucida Console'>(</font>stepa <font color='#5555FF'>*</font> stepb<font face='Lucida Console'>)</font>;
                    zmat[nf <font color='#5555FF'>+</font> nfx <font color='#5555FF'>*</font> zmat_dim1] <font color='#5555FF'>=</font> std::<font color='#BB00BB'>sqrt</font><font face='Lucida Console'>(</font>half<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> rhosq;
                    zmat[nf <font color='#5555FF'>-</font> n <font color='#5555FF'>+</font> nfx <font color='#5555FF'>*</font> zmat_dim1] <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>zmat[nfx <font color='#5555FF'>*</font> zmat_dim1 <font color='#5555FF'>+</font> <font color='#979000'>1</font>] <font color='#5555FF'>-</font> 
                        zmat[nf <font color='#5555FF'>+</font> nfx <font color='#5555FF'>*</font> zmat_dim1];
                <b>}</b>

                <font color='#009900'>/*     Set the off-diagonal second derivatives of the Lagrange functions and */</font>
                <font color='#009900'>/*     the initial quadratic model. */</font>

            <b>}</b> <font color='#0000FF'>else</font> <b>{</b>
                ih <font color='#5555FF'>=</font> ipt <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>ipt <font color='#5555FF'>-</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> <font color='#979000'>2</font> <font color='#5555FF'>+</font> jpt;
                zmat[nfx <font color='#5555FF'>*</font> zmat_dim1 <font color='#5555FF'>+</font> <font color='#979000'>1</font>] <font color='#5555FF'>=</font> recip;
                zmat[nf <font color='#5555FF'>+</font> nfx <font color='#5555FF'>*</font> zmat_dim1] <font color='#5555FF'>=</font> recip;
                zmat[ipt <font color='#5555FF'>+</font> <font color='#979000'>1</font> <font color='#5555FF'>+</font> nfx <font color='#5555FF'>*</font> zmat_dim1] <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>recip;
                zmat[jpt <font color='#5555FF'>+</font> <font color='#979000'>1</font> <font color='#5555FF'>+</font> nfx <font color='#5555FF'>*</font> zmat_dim1] <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>recip;
                temp <font color='#5555FF'>=</font> xpt[nf <font color='#5555FF'>+</font> ipt <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>*</font> xpt[nf <font color='#5555FF'>+</font> jpt <font color='#5555FF'>*</font> xpt_dim1];
                hq[ih] <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>fbeg <font color='#5555FF'>-</font> fval[ipt <font color='#5555FF'>+</font> <font color='#979000'>1</font>] <font color='#5555FF'>-</font> fval[jpt <font color='#5555FF'>+</font> <font color='#979000'>1</font>] <font color='#5555FF'>+</font> f<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> temp;
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>nf <font color='#5555FF'>&lt;</font> npt <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> nf <font color='#5555FF'>&lt;</font> maxfun<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>goto</font> L50;
            <b>}</b>

        <b>}</b> <font color='#009900'>/* prelim_ */</font>

    <font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> funct<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='rescue_'></a>rescue_</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> funct<font color='#5555FF'>&amp;</font> calfun,
            <font color='#0000FF'>const</font> integer n,
            <font color='#0000FF'>const</font> integer npt,
            <font color='#0000FF'>const</font> doublereal <font color='#5555FF'>*</font>xl, 
            <font color='#0000FF'>const</font> doublereal <font color='#5555FF'>*</font>xu,
            <font color='#0000FF'>const</font> integer maxfun,
            doublereal <font color='#5555FF'>*</font>xbase, 
            doublereal <font color='#5555FF'>*</font>xpt, 
            doublereal <font color='#5555FF'>*</font>fval,
            doublereal <font color='#5555FF'>*</font>xopt,
            doublereal <font color='#5555FF'>*</font>gopt,
            doublereal <font color='#5555FF'>*</font>hq, 
            doublereal <font color='#5555FF'>*</font>pq,
            doublereal <font color='#5555FF'>*</font>bmat,
            doublereal <font color='#5555FF'>*</font>zmat, 
            <font color='#0000FF'>const</font> integer ndim,
            doublereal <font color='#5555FF'>*</font>sl,
            doublereal <font color='#5555FF'>*</font>su,
            integer<font color='#5555FF'>&amp;</font> nf, 
            <font color='#0000FF'>const</font> doublereal delta,
            integer<font color='#5555FF'>&amp;</font> kopt,
            doublereal <font color='#5555FF'>*</font>vlag,
            doublereal <font color='#5555FF'>*</font> ptsaux,
            doublereal <font color='#5555FF'>*</font>ptsid,
            doublereal <font color='#5555FF'>*</font>w
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            <font color='#009900'>/* System generated locals */</font>
            integer xpt_dim1, xpt_offset, bmat_dim1, bmat_offset, zmat_dim1, 
            zmat_offset, i__1, i__2, i__3;
            doublereal d__1, d__2, d__3, d__4;


            <font color='#009900'>/* Local variables */</font>
            doublereal f;
            integer i__, j, k, ih, jp, ip, iq, np, iw;
            doublereal xp <font color='#5555FF'>=</font> <font color='#979000'>0</font>, xq <font color='#5555FF'>=</font> <font color='#979000'>0</font>, den <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            integer ihp <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            doublereal one;
            integer ihq, jpn, kpt;
            doublereal sum <font color='#5555FF'>=</font> <font color='#979000'>0</font>, diff <font color='#5555FF'>=</font> <font color='#979000'>0</font>, half <font color='#5555FF'>=</font> <font color='#979000'>0</font>, beta <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            integer kold;
            doublereal winc;
            integer nrem, knew;
            doublereal temp, bsum;
            integer nptm;
            doublereal zero <font color='#5555FF'>=</font> <font color='#979000'>0</font>, hdiag <font color='#5555FF'>=</font> <font color='#979000'>0</font>, fbase <font color='#5555FF'>=</font> <font color='#979000'>0</font>, sfrac <font color='#5555FF'>=</font> <font color='#979000'>0</font>, denom <font color='#5555FF'>=</font> <font color='#979000'>0</font>, vquad <font color='#5555FF'>=</font> <font color='#979000'>0</font>, sumpq <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            doublereal dsqmin, distsq, vlmxsq;



            <font color='#009900'>/*     The arguments N, NPT, XL, XU, IPRINT, MAXFUN, XBASE, XPT, FVAL, XOPT, */</font>
            <font color='#009900'>/*       GOPT, HQ, PQ, BMAT, ZMAT, NDIM, SL and SU have the same meanings as */</font>
            <font color='#009900'>/*       the corresponding arguments of BOBYQB on the entry to RESCUE. */</font>
            <font color='#009900'>/*     NF is maintained as the number of calls of CALFUN so far, except that */</font>
            <font color='#009900'>/*       NF is set to -1 if the value of MAXFUN prevents further progress. */</font>
            <font color='#009900'>/*     KOPT is maintained so that FVAL(KOPT) is the least calculated function */</font>
            <font color='#009900'>/*       value. Its correct value must be given on entry. It is updated if a */</font>
            <font color='#009900'>/*       new least function value is found, but the corresponding changes to */</font>
            <font color='#009900'>/*       XOPT and GOPT have to be made later by the calling program. */</font>
            <font color='#009900'>/*     DELTA is the current trust region radius. */</font>
            <font color='#009900'>/*     VLAG is a working space vector that will be used for the values of the */</font>
            <font color='#009900'>/*       provisional Lagrange functions at each of the interpolation points. */</font>
            <font color='#009900'>/*       They are part of a product that requires VLAG to be of length NDIM. */</font>
            <font color='#009900'>/*     PTSAUX is also a working space array. For J=1,2,...,N, PTSAUX(1,J) and */</font>
            <font color='#009900'>/*       PTSAUX(2,J) specify the two positions of provisional interpolation */</font>
            <font color='#009900'>/*       points when a nonzero step is taken along e_J (the J-th coordinate */</font>
            <font color='#009900'>/*       direction) through XBASE+XOPT, as specified below. Usually these */</font>
            <font color='#009900'>/*       steps have length DELTA, but other lengths are chosen if necessary */</font>
            <font color='#009900'>/*       in order to satisfy the given bounds on the variables. */</font>
            <font color='#009900'>/*     PTSID is also a working space array. It has NPT components that denote */</font>
            <font color='#009900'>/*       provisional new positions of the original interpolation points, in */</font>
            <font color='#009900'>/*       case changes are needed to restore the linear independence of the */</font>
            <font color='#009900'>/*       interpolation conditions. The K-th point is a candidate for change */</font>
            <font color='#009900'>/*       if and only if PTSID(K) is nonzero. In this case let p and q be the */</font>
            <font color='#009900'>/*       integer parts of PTSID(K) and (PTSID(K)-p) multiplied by N+1. If p */</font>
            <font color='#009900'>/*       and q are both positive, the step from XBASE+XOPT to the new K-th */</font>
            <font color='#009900'>/*       interpolation point is PTSAUX(1,p)*e_p + PTSAUX(1,q)*e_q. Otherwise */</font>
            <font color='#009900'>/*       the step is PTSAUX(1,p)*e_p or PTSAUX(2,q)*e_q in the cases q=0 or */</font>
            <font color='#009900'>/*       p=0, respectively. */</font>
            <font color='#009900'>/*     The first NDIM+NPT elements of the array W are used for working space. */</font>
            <font color='#009900'>/*     The final elements of BMAT and ZMAT are set in a well-conditioned way */</font>
            <font color='#009900'>/*       to the values that are appropriate for the new interpolation points. */</font>
            <font color='#009900'>/*     The elements of GOPT, HQ and PQ are also revised to the values that are */</font>
            <font color='#009900'>/*       appropriate to the final quadratic model. */</font>

            <font color='#009900'>/*     Set some constants. */</font>

            <font color='#009900'>/* Parameter adjustments */</font>
            zmat_dim1 <font color='#5555FF'>=</font> npt;
            zmat_offset <font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>+</font> zmat_dim1;
            zmat <font color='#5555FF'>-</font><font color='#5555FF'>=</font> zmat_offset;
            xpt_dim1 <font color='#5555FF'>=</font> npt;
            xpt_offset <font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>+</font> xpt_dim1;
            xpt <font color='#5555FF'>-</font><font color='#5555FF'>=</font> xpt_offset;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>xl;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>xu;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>xbase;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>fval;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>xopt;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>gopt;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>hq;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>pq;
            bmat_dim1 <font color='#5555FF'>=</font> ndim;
            bmat_offset <font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>+</font> bmat_dim1;
            bmat <font color='#5555FF'>-</font><font color='#5555FF'>=</font> bmat_offset;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>sl;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>su;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>vlag;
            ptsaux <font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font color='#979000'>3</font>;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>ptsid;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>w;

            <font color='#009900'>/* Function Body */</font>
            half <font color='#5555FF'>=</font> .<font color='#979000'>5</font>;
            one <font color='#5555FF'>=</font> <font color='#979000'>1.</font>;
            zero <font color='#5555FF'>=</font> <font color='#979000'>0.</font>;
            np <font color='#5555FF'>=</font> n <font color='#5555FF'>+</font> <font color='#979000'>1</font>;
            sfrac <font color='#5555FF'>=</font> half <font color='#5555FF'>/</font> <font face='Lucida Console'>(</font>doublereal<font face='Lucida Console'>)</font> np;
            nptm <font color='#5555FF'>=</font> npt <font color='#5555FF'>-</font> np;

            <font color='#009900'>/*     Shift the interpolation points so that XOPT becomes the origin, and set */</font>
            <font color='#009900'>/*     the elements of ZMAT to zero. The value of SUMPQ is required in the */</font>
            <font color='#009900'>/*     updating of HQ below. The squares of the distances from XOPT to the */</font>
            <font color='#009900'>/*     other interpolation points are set at the end of W. Increments of WINC */</font>
            <font color='#009900'>/*     may be added later to these squares to balance the consideration of */</font>
            <font color='#009900'>/*     the choice of point that is going to become current. */</font>

            sumpq <font color='#5555FF'>=</font> zero;
            winc <font color='#5555FF'>=</font> zero;
            i__1 <font color='#5555FF'>=</font> npt;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                distsq <font color='#5555FF'>=</font> zero;
                i__2 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                    xpt[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>-</font><font color='#5555FF'>=</font> xopt[j];
                    <font color='#009900'>/* L10: */</font>
                    <font color='#009900'>/* Computing 2nd power */</font>
                    d__1 <font color='#5555FF'>=</font> xpt[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1];
                    distsq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                <b>}</b>
                sumpq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> pq[k];
                w[ndim <font color='#5555FF'>+</font> k] <font color='#5555FF'>=</font> distsq;
                winc <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>winc,distsq<font face='Lucida Console'>)</font>;
                i__2 <font color='#5555FF'>=</font> nptm;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L20: */</font>
                    zmat[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1] <font color='#5555FF'>=</font> zero;
                <b>}</b>
            <b>}</b>

            <font color='#009900'>/*     Update HQ so that HQ and PQ define the second derivatives of the model */</font>
            <font color='#009900'>/*     after XBASE has been shifted to the trust region centre. */</font>

            ih <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            i__2 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                w[j] <font color='#5555FF'>=</font> half <font color='#5555FF'>*</font> sumpq <font color='#5555FF'>*</font> xopt[j];
                i__1 <font color='#5555FF'>=</font> npt;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L30: */</font>
                    w[j] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> pq[k] <font color='#5555FF'>*</font> xpt[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1];
                <b>}</b>
                i__1 <font color='#5555FF'>=</font> j;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#5555FF'>+</font><font color='#5555FF'>+</font>ih;
                    <font color='#009900'>/* L40: */</font>
                    hq[ih] <font color='#5555FF'>=</font> hq[ih] <font color='#5555FF'>+</font> w[i__] <font color='#5555FF'>*</font> xopt[j] <font color='#5555FF'>+</font> w[j] <font color='#5555FF'>*</font> xopt[i__];
                <b>}</b>
            <b>}</b>

            <font color='#009900'>/*     Shift XBASE, SL, SU and XOPT. Set the elements of BMAT to zero, and */</font>
            <font color='#009900'>/*     also set the elements of PTSAUX. */</font>

            i__1 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                xbase[j] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> xopt[j];
                sl[j] <font color='#5555FF'>-</font><font color='#5555FF'>=</font> xopt[j];
                su[j] <font color='#5555FF'>-</font><font color='#5555FF'>=</font> xopt[j];
                xopt[j] <font color='#5555FF'>=</font> zero;
                <font color='#009900'>/* Computing MIN */</font>
                d__1 <font color='#5555FF'>=</font> delta, d__2 <font color='#5555FF'>=</font> su[j];
                ptsaux[<font face='Lucida Console'>(</font>j <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>] <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
                <font color='#009900'>/* Computing MAX */</font>
                d__1 <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font face='Lucida Console'>(</font>delta<font face='Lucida Console'>)</font>, d__2 <font color='#5555FF'>=</font> sl[j];
                ptsaux[<font face='Lucida Console'>(</font>j <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>2</font>] <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ptsaux[<font face='Lucida Console'>(</font>j <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>] <font color='#5555FF'>+</font> ptsaux[<font face='Lucida Console'>(</font>j <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>2</font>] <font color='#5555FF'>&lt;</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    temp <font color='#5555FF'>=</font> ptsaux[<font face='Lucida Console'>(</font>j <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>];
                    ptsaux[<font face='Lucida Console'>(</font>j <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>] <font color='#5555FF'>=</font> ptsaux[<font face='Lucida Console'>(</font>j <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>2</font>];
                    ptsaux[<font face='Lucida Console'>(</font>j <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>2</font>] <font color='#5555FF'>=</font> temp;
                <b>}</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>d__2 <font color='#5555FF'>=</font> ptsaux[<font face='Lucida Console'>(</font>j <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>2</font>], std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>d__2<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> half <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>d__1 <font color='#5555FF'>=</font> ptsaux[<font face='Lucida Console'>(</font>
                            j <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>], std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>d__1<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <b>{</b>
                    ptsaux[<font face='Lucida Console'>(</font>j <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>2</font>] <font color='#5555FF'>=</font> half <font color='#5555FF'>*</font> ptsaux[<font face='Lucida Console'>(</font>j <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>];
                <b>}</b>
                i__2 <font color='#5555FF'>=</font> ndim;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L50: */</font>
                    bmat[i__ <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>=</font> zero;
                <b>}</b>
            <b>}</b>
            fbase <font color='#5555FF'>=</font> fval[kopt];

            <font color='#009900'>/*     Set the identifiers of the artificial interpolation points that are */</font>
            <font color='#009900'>/*     along a coordinate direction from XOPT, and set the corresponding */</font>
            <font color='#009900'>/*     nonzero elements of BMAT and ZMAT. */</font>

            ptsid[<font color='#979000'>1</font>] <font color='#5555FF'>=</font> sfrac;
            i__2 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                jp <font color='#5555FF'>=</font> j <font color='#5555FF'>+</font> <font color='#979000'>1</font>;
                jpn <font color='#5555FF'>=</font> jp <font color='#5555FF'>+</font> n;
                ptsid[jp] <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>doublereal<font face='Lucida Console'>)</font> j <font color='#5555FF'>+</font> sfrac;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>jpn <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> npt<font face='Lucida Console'>)</font> <b>{</b>
                    ptsid[jpn] <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>doublereal<font face='Lucida Console'>)</font> j <font color='#5555FF'>/</font> <font face='Lucida Console'>(</font>doublereal<font face='Lucida Console'>)</font> np <font color='#5555FF'>+</font> sfrac;
                    temp <font color='#5555FF'>=</font> one <font color='#5555FF'>/</font> <font face='Lucida Console'>(</font>ptsaux[<font face='Lucida Console'>(</font>j <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>] <font color='#5555FF'>-</font> ptsaux[<font face='Lucida Console'>(</font>j <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>2</font>]<font face='Lucida Console'>)</font>;
                    bmat[jp <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>temp <font color='#5555FF'>+</font> one <font color='#5555FF'>/</font> ptsaux[<font face='Lucida Console'>(</font>j <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>];
                    bmat[jpn <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>=</font> temp <font color='#5555FF'>+</font> one <font color='#5555FF'>/</font> ptsaux[<font face='Lucida Console'>(</font>j <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>2</font>];
                    bmat[j <font color='#5555FF'>*</font> bmat_dim1 <font color='#5555FF'>+</font> <font color='#979000'>1</font>] <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>bmat[jp <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>-</font> bmat[jpn <font color='#5555FF'>+</font> 
                        j <font color='#5555FF'>*</font> bmat_dim1];
                    zmat[j <font color='#5555FF'>*</font> zmat_dim1 <font color='#5555FF'>+</font> <font color='#979000'>1</font>] <font color='#5555FF'>=</font> std::<font color='#BB00BB'>sqrt</font><font face='Lucida Console'>(</font><font color='#979000'>2.</font><font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> <font face='Lucida Console'>(</font>d__1 <font color='#5555FF'>=</font> ptsaux[<font face='Lucida Console'>(</font>j <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>] 
                                                          <font color='#5555FF'>*</font> ptsaux[<font face='Lucida Console'>(</font>j <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>2</font>], std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>d__1<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    zmat[jp <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1] <font color='#5555FF'>=</font> zmat[j <font color='#5555FF'>*</font> zmat_dim1 <font color='#5555FF'>+</font> <font color='#979000'>1</font>] <font color='#5555FF'>*</font> ptsaux[<font face='Lucida Console'>(</font>j <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> 
                                                                                 <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>2</font>] <font color='#5555FF'>*</font> temp;
                    zmat[jpn <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1] <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>zmat[j <font color='#5555FF'>*</font> zmat_dim1 <font color='#5555FF'>+</font> <font color='#979000'>1</font>] <font color='#5555FF'>*</font> ptsaux[<font face='Lucida Console'>(</font>j 
                                                                                   <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>] <font color='#5555FF'>*</font> temp;
                <b>}</b> <font color='#0000FF'>else</font> <b>{</b>
                    bmat[j <font color='#5555FF'>*</font> bmat_dim1 <font color='#5555FF'>+</font> <font color='#979000'>1</font>] <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>one <font color='#5555FF'>/</font> ptsaux[<font face='Lucida Console'>(</font>j <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>];
                    bmat[jp <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>=</font> one <font color='#5555FF'>/</font> ptsaux[<font face='Lucida Console'>(</font>j <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>];
                    <font color='#009900'>/* Computing 2nd power */</font>
                    d__1 <font color='#5555FF'>=</font> ptsaux[<font face='Lucida Console'>(</font>j <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>];
                    bmat[j <font color='#5555FF'>+</font> npt <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>half <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>d__1 <font color='#5555FF'>*</font> d__1<font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#009900'>/* L60: */</font>
            <b>}</b>

            <font color='#009900'>/*     Set any remaining identifiers with their nonzero elements of ZMAT. */</font>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>npt <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> n <font color='#5555FF'>+</font> np<font face='Lucida Console'>)</font> <b>{</b>
                i__2 <font color='#5555FF'>=</font> npt;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> np <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                    iw <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>integer<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>doublereal<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>-</font> np<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> half<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> <font face='Lucida Console'>(</font>doublereal<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>n<font face='Lucida Console'>)</font>
                    <font face='Lucida Console'>)</font>;
                    ip <font color='#5555FF'>=</font> k <font color='#5555FF'>-</font> np <font color='#5555FF'>-</font> iw <font color='#5555FF'>*</font> n;
                    iq <font color='#5555FF'>=</font> ip <font color='#5555FF'>+</font> iw;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>iq <font color='#5555FF'>&gt;</font> n<font face='Lucida Console'>)</font> <b>{</b>
                        iq <font color='#5555FF'>-</font><font color='#5555FF'>=</font> n;
                    <b>}</b>
                    ptsid[k] <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>doublereal<font face='Lucida Console'>)</font> ip <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font>doublereal<font face='Lucida Console'>)</font> iq <font color='#5555FF'>/</font> <font face='Lucida Console'>(</font>doublereal<font face='Lucida Console'>)</font> np <font color='#5555FF'>+</font> 
                        sfrac;
                    temp <font color='#5555FF'>=</font> one <font color='#5555FF'>/</font> <font face='Lucida Console'>(</font>ptsaux[<font face='Lucida Console'>(</font>ip <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>] <font color='#5555FF'>*</font> ptsaux[<font face='Lucida Console'>(</font>iq <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>]<font face='Lucida Console'>)</font>;
                    zmat[<font face='Lucida Console'>(</font>k <font color='#5555FF'>-</font> np<font face='Lucida Console'>)</font> <font color='#5555FF'>*</font> zmat_dim1 <font color='#5555FF'>+</font> <font color='#979000'>1</font>] <font color='#5555FF'>=</font> temp;
                    zmat[ip <font color='#5555FF'>+</font> <font color='#979000'>1</font> <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>-</font> np<font face='Lucida Console'>)</font> <font color='#5555FF'>*</font> zmat_dim1] <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>temp;
                    zmat[iq <font color='#5555FF'>+</font> <font color='#979000'>1</font> <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>-</font> np<font face='Lucida Console'>)</font> <font color='#5555FF'>*</font> zmat_dim1] <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>temp;
                    <font color='#009900'>/* L70: */</font>
                    zmat[k <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>-</font> np<font face='Lucida Console'>)</font> <font color='#5555FF'>*</font> zmat_dim1] <font color='#5555FF'>=</font> temp;
                <b>}</b>
            <b>}</b>
            nrem <font color='#5555FF'>=</font> npt;
            kold <font color='#5555FF'>=</font> <font color='#979000'>1</font>;
            knew <font color='#5555FF'>=</font> kopt;

            <font color='#009900'>/*     Reorder the provisional points in the way that exchanges PTSID(KOLD) */</font>
            <font color='#009900'>/*     with PTSID(KNEW). */</font>

L80:
            i__2 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                temp <font color='#5555FF'>=</font> bmat[kold <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1];
                bmat[kold <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>=</font> bmat[knew <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1];
                <font color='#009900'>/* L90: */</font>
                bmat[knew <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>=</font> temp;
            <b>}</b>
            i__2 <font color='#5555FF'>=</font> nptm;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                temp <font color='#5555FF'>=</font> zmat[kold <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1];
                zmat[kold <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1] <font color='#5555FF'>=</font> zmat[knew <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1];
                <font color='#009900'>/* L100: */</font>
                zmat[knew <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1] <font color='#5555FF'>=</font> temp;
            <b>}</b>
            ptsid[kold] <font color='#5555FF'>=</font> ptsid[knew];
            ptsid[knew] <font color='#5555FF'>=</font> zero;
            w[ndim <font color='#5555FF'>+</font> knew] <font color='#5555FF'>=</font> zero;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>nrem;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>knew <font color='#5555FF'>!</font><font color='#5555FF'>=</font> kopt<font face='Lucida Console'>)</font> <b>{</b>
                temp <font color='#5555FF'>=</font> vlag[kold];
                vlag[kold] <font color='#5555FF'>=</font> vlag[knew];
                vlag[knew] <font color='#5555FF'>=</font> temp;

                <font color='#009900'>/*     Update the BMAT and ZMAT matrices so that the status of the KNEW-th */</font>
                <font color='#009900'>/*     interpolation point can be changed from provisional to original. The */</font>
                <font color='#009900'>/*     branch to label 350 occurs if all the original points are reinstated. */</font>
                <font color='#009900'>/*     The nonnegative values of W(NDIM+K) are required in the search below. */</font>

                <font color='#BB00BB'>update_</font><font face='Lucida Console'>(</font>n, npt, <font color='#5555FF'>&amp;</font>bmat[bmat_offset], <font color='#5555FF'>&amp;</font>zmat[zmat_offset], ndim, <font color='#5555FF'>&amp;</font>vlag[<font color='#979000'>1</font>], 
                        beta, denom, knew, <font color='#5555FF'>&amp;</font>w[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>nrem <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#0000FF'>goto</font> L350;
                <b>}</b>
                i__2 <font color='#5555FF'>=</font> npt;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L110: */</font>
                    w[ndim <font color='#5555FF'>+</font> k] <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>d__1 <font color='#5555FF'>=</font> w[ndim <font color='#5555FF'>+</font> k], std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>d__1<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>

            <font color='#009900'>/*     Pick the index KNEW of an original interpolation point that has not */</font>
            <font color='#009900'>/*     yet replaced one of the provisional interpolation points, giving */</font>
            <font color='#009900'>/*     attention to the closeness to XOPT and to previous tries with KNEW. */</font>

L120:
            dsqmin <font color='#5555FF'>=</font> zero;
            i__2 <font color='#5555FF'>=</font> npt;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>w[ndim <font color='#5555FF'>+</font> k] <font color='#5555FF'>&gt;</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>dsqmin <font color='#5555FF'>=</font><font color='#5555FF'>=</font> zero <font color='#5555FF'>|</font><font color='#5555FF'>|</font> w[ndim <font color='#5555FF'>+</font> k] <font color='#5555FF'>&lt;</font> dsqmin<font face='Lucida Console'>)</font> <b>{</b>
                        knew <font color='#5555FF'>=</font> k;
                        dsqmin <font color='#5555FF'>=</font> w[ndim <font color='#5555FF'>+</font> k];
                    <b>}</b>
                <b>}</b>
                <font color='#009900'>/* L130: */</font>
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>dsqmin <font color='#5555FF'>=</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>goto</font> L260;
            <b>}</b>

            <font color='#009900'>/*     Form the W-vector of the chosen original interpolation point. */</font>

            i__2 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#009900'>/* L140: */</font>
                w[npt <font color='#5555FF'>+</font> j] <font color='#5555FF'>=</font> xpt[knew <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1];
            <b>}</b>
            i__2 <font color='#5555FF'>=</font> npt;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                sum <font color='#5555FF'>=</font> zero;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font><font color='#5555FF'>=</font> kopt<font face='Lucida Console'>)</font> <b>{</b>
                <b>}</b> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ptsid[k] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    i__1 <font color='#5555FF'>=</font> n;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#009900'>/* L150: */</font>
                        sum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> w[npt <font color='#5555FF'>+</font> j] <font color='#5555FF'>*</font> xpt[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1];
                    <b>}</b>
                <b>}</b> <font color='#0000FF'>else</font> <b>{</b>
                    ip <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>integer<font face='Lucida Console'>)</font> ptsid[k];
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ip <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                        sum <font color='#5555FF'>=</font> w[npt <font color='#5555FF'>+</font> ip] <font color='#5555FF'>*</font> ptsaux[<font face='Lucida Console'>(</font>ip <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>];
                    <b>}</b>
                    iq <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>integer<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>doublereal<font face='Lucida Console'>)</font> np <font color='#5555FF'>*</font> ptsid[k] <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font>doublereal<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>ip <font color='#5555FF'>*</font> 
                                                                               np<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>iq <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                        iw <font color='#5555FF'>=</font> <font color='#979000'>1</font>;
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ip <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                            iw <font color='#5555FF'>=</font> <font color='#979000'>2</font>;
                        <b>}</b>
                        sum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> w[npt <font color='#5555FF'>+</font> iq] <font color='#5555FF'>*</font> ptsaux[iw <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font>iq <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>];
                    <b>}</b>
                <b>}</b>
                <font color='#009900'>/* L160: */</font>
                w[k] <font color='#5555FF'>=</font> half <font color='#5555FF'>*</font> sum <font color='#5555FF'>*</font> sum;
            <b>}</b>

            <font color='#009900'>/*     Calculate VLAG and BETA for the required updating of the H matrix if */</font>
            <font color='#009900'>/*     XPT(KNEW,.) is reinstated in the set of interpolation points. */</font>

            i__2 <font color='#5555FF'>=</font> npt;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                sum <font color='#5555FF'>=</font> zero;
                i__1 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L170: */</font>
                    sum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> bmat[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>*</font> w[npt <font color='#5555FF'>+</font> j];
                <b>}</b>
                <font color='#009900'>/* L180: */</font>
                vlag[k] <font color='#5555FF'>=</font> sum;
            <b>}</b>
            beta <font color='#5555FF'>=</font> zero;
            i__2 <font color='#5555FF'>=</font> nptm;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                sum <font color='#5555FF'>=</font> zero;
                i__1 <font color='#5555FF'>=</font> npt;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L190: */</font>
                    sum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> zmat[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1] <font color='#5555FF'>*</font> w[k];
                <b>}</b>
                beta <font color='#5555FF'>-</font><font color='#5555FF'>=</font> sum <font color='#5555FF'>*</font> sum;
                i__1 <font color='#5555FF'>=</font> npt;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L200: */</font>
                    vlag[k] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> sum <font color='#5555FF'>*</font> zmat[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1];
                <b>}</b>
            <b>}</b>
            bsum <font color='#5555FF'>=</font> zero;
            distsq <font color='#5555FF'>=</font> zero;
            i__1 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                sum <font color='#5555FF'>=</font> zero;
                i__2 <font color='#5555FF'>=</font> npt;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L210: */</font>
                    sum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> bmat[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>*</font> w[k];
                <b>}</b>
                jp <font color='#5555FF'>=</font> j <font color='#5555FF'>+</font> npt;
                bsum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> sum <font color='#5555FF'>*</font> w[jp];
                i__2 <font color='#5555FF'>=</font> ndim;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>ip <font color='#5555FF'>=</font> npt <font color='#5555FF'>+</font> <font color='#979000'>1</font>; ip <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>ip<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L220: */</font>
                    sum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> bmat[ip <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>*</font> w[ip];
                <b>}</b>
                bsum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> sum <font color='#5555FF'>*</font> w[jp];
                vlag[jp] <font color='#5555FF'>=</font> sum;
                <font color='#009900'>/* L230: */</font>
                <font color='#009900'>/* Computing 2nd power */</font>
                d__1 <font color='#5555FF'>=</font> xpt[knew <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1];
                distsq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
            <b>}</b>
            beta <font color='#5555FF'>=</font> half <font color='#5555FF'>*</font> distsq <font color='#5555FF'>*</font> distsq <font color='#5555FF'>+</font> beta <font color='#5555FF'>-</font> bsum;
            vlag[kopt] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> one;

            <font color='#009900'>/*     KOLD is set to the index of the provisional interpolation point that is */</font>
            <font color='#009900'>/*     going to be deleted to make way for the KNEW-th original interpolation */</font>
            <font color='#009900'>/*     point. The choice of KOLD is governed by the avoidance of a small value */</font>
            <font color='#009900'>/*     of the denominator in the updating calculation of UPDATE. */</font>

            denom <font color='#5555FF'>=</font> zero;
            vlmxsq <font color='#5555FF'>=</font> zero;
            i__1 <font color='#5555FF'>=</font> npt;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ptsid[k] <font color='#5555FF'>!</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    hdiag <font color='#5555FF'>=</font> zero;
                    i__2 <font color='#5555FF'>=</font> nptm;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#009900'>/* L240: */</font>
                        <font color='#009900'>/* Computing 2nd power */</font>
                        d__1 <font color='#5555FF'>=</font> zmat[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1];
                        hdiag <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                    <b>}</b>
                    <font color='#009900'>/* Computing 2nd power */</font>
                    d__1 <font color='#5555FF'>=</font> vlag[k];
                    den <font color='#5555FF'>=</font> beta <font color='#5555FF'>*</font> hdiag <font color='#5555FF'>+</font> d__1 <font color='#5555FF'>*</font> d__1;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>den <font color='#5555FF'>&gt;</font> denom<font face='Lucida Console'>)</font> <b>{</b>
                        kold <font color='#5555FF'>=</font> k;
                        denom <font color='#5555FF'>=</font> den;
                    <b>}</b>
                <b>}</b>
                <font color='#009900'>/* L250: */</font>
                <font color='#009900'>/* Computing MAX */</font>
                <font color='#009900'>/* Computing 2nd power */</font>
                d__3 <font color='#5555FF'>=</font> vlag[k];
                d__1 <font color='#5555FF'>=</font> vlmxsq, d__2 <font color='#5555FF'>=</font> d__3 <font color='#5555FF'>*</font> d__3;
                vlmxsq <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>denom <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> vlmxsq <font color='#5555FF'>*</font> .<font color='#979000'>01</font><font face='Lucida Console'>)</font> <b>{</b>
                w[ndim <font color='#5555FF'>+</font> knew] <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>w[ndim <font color='#5555FF'>+</font> knew] <font color='#5555FF'>-</font> winc;
                <font color='#0000FF'>goto</font> L120;
            <b>}</b>
            <font color='#0000FF'>goto</font> L80;

            <font color='#009900'>/*     When label 260 is reached, all the final positions of the interpolation */</font>
            <font color='#009900'>/*     points have been chosen although any changes have not been included yet */</font>
            <font color='#009900'>/*     in XPT. Also the final BMAT and ZMAT matrices are complete, but, apart */</font>
            <font color='#009900'>/*     from the shift of XBASE, the updating of the quadratic model remains to */</font>
            <font color='#009900'>/*     be done. The following cycle through the new interpolation points begins */</font>
            <font color='#009900'>/*     by putting the new point in XPT(KPT,.) and by setting PQ(KPT) to zero, */</font>
            <font color='#009900'>/*     except that a RETURN occurs if MAXFUN prohibits another value of F. */</font>

L260:
            i__1 <font color='#5555FF'>=</font> npt;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>kpt <font color='#5555FF'>=</font> <font color='#979000'>1</font>; kpt <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>kpt<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ptsid[kpt] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#0000FF'>goto</font> L340;
                <b>}</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>nf <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> maxfun<font face='Lucida Console'>)</font> <b>{</b>
                    nf <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
                    <font color='#0000FF'>goto</font> L350;
                <b>}</b>
                ih <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                i__2 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                    w[j] <font color='#5555FF'>=</font> xpt[kpt <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1];
                    xpt[kpt <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>=</font> zero;
                    temp <font color='#5555FF'>=</font> pq[kpt] <font color='#5555FF'>*</font> w[j];
                    i__3 <font color='#5555FF'>=</font> j;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__3; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#5555FF'>+</font><font color='#5555FF'>+</font>ih;
                        <font color='#009900'>/* L270: */</font>
                        hq[ih] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp <font color='#5555FF'>*</font> w[i__];
                    <b>}</b>
                <b>}</b>
                pq[kpt] <font color='#5555FF'>=</font> zero;
                ip <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>integer<font face='Lucida Console'>)</font> ptsid[kpt];
                iq <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>integer<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>doublereal<font face='Lucida Console'>)</font> np <font color='#5555FF'>*</font> ptsid[kpt] <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font>doublereal<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>ip <font color='#5555FF'>*</font> np<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    ;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ip <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                    xp <font color='#5555FF'>=</font> ptsaux[<font face='Lucida Console'>(</font>ip <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>];
                    xpt[kpt <font color='#5555FF'>+</font> ip <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>=</font> xp;
                <b>}</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>iq <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                    xq <font color='#5555FF'>=</font> ptsaux[<font face='Lucida Console'>(</font>iq <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>];
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ip <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                        xq <font color='#5555FF'>=</font> ptsaux[<font face='Lucida Console'>(</font>iq <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>2</font>];
                    <b>}</b>
                    xpt[kpt <font color='#5555FF'>+</font> iq <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>=</font> xq;
                <b>}</b>

                <font color='#009900'>/*     Set VQUAD to the value of the current model at the new point. */</font>

                vquad <font color='#5555FF'>=</font> fbase;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ip <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                    ihp <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>ip <font color='#5555FF'>+</font> ip <font color='#5555FF'>*</font> ip<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> <font color='#979000'>2</font>;
                    vquad <font color='#5555FF'>+</font><font color='#5555FF'>=</font> xp <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>gopt[ip] <font color='#5555FF'>+</font> half <font color='#5555FF'>*</font> xp <font color='#5555FF'>*</font> hq[ihp]<font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>iq <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                    ihq <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>iq <font color='#5555FF'>+</font> iq <font color='#5555FF'>*</font> iq<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> <font color='#979000'>2</font>;
                    vquad <font color='#5555FF'>+</font><font color='#5555FF'>=</font> xq <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>gopt[iq] <font color='#5555FF'>+</font> half <font color='#5555FF'>*</font> xq <font color='#5555FF'>*</font> hq[ihq]<font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ip <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                        iw <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>ihp,ihq<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font>i__3 <font color='#5555FF'>=</font> ip <font color='#5555FF'>-</font> iq, std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>i__3<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                        vquad <font color='#5555FF'>+</font><font color='#5555FF'>=</font> xp <font color='#5555FF'>*</font> xq <font color='#5555FF'>*</font> hq[iw];
                    <b>}</b>
                <b>}</b>
                i__3 <font color='#5555FF'>=</font> npt;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__3; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                    temp <font color='#5555FF'>=</font> zero;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ip <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                        temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> xp <font color='#5555FF'>*</font> xpt[k <font color='#5555FF'>+</font> ip <font color='#5555FF'>*</font> xpt_dim1];
                    <b>}</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>iq <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                        temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> xq <font color='#5555FF'>*</font> xpt[k <font color='#5555FF'>+</font> iq <font color='#5555FF'>*</font> xpt_dim1];
                    <b>}</b>
                    <font color='#009900'>/* L280: */</font>
                    vquad <font color='#5555FF'>+</font><font color='#5555FF'>=</font> half <font color='#5555FF'>*</font> pq[k] <font color='#5555FF'>*</font> temp <font color='#5555FF'>*</font> temp;
                <b>}</b>

                <font color='#009900'>/*     Calculate F at the new interpolation point, and set DIFF to the factor */</font>
                <font color='#009900'>/*     that is going to multiply the KPT-th Lagrange function when the model */</font>
                <font color='#009900'>/*     is updated to provide interpolation to the new function value. */</font>

                i__3 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__3; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* Computing MIN */</font>
                    <font color='#009900'>/* Computing MAX */</font>
                    d__3 <font color='#5555FF'>=</font> xl[i__], d__4 <font color='#5555FF'>=</font> xbase[i__] <font color='#5555FF'>+</font> xpt[kpt <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> xpt_dim1];
                    d__1 <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__3,d__4<font face='Lucida Console'>)</font>, d__2 <font color='#5555FF'>=</font> xu[i__];
                    w[i__] <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xpt[kpt <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> sl[i__]<font face='Lucida Console'>)</font> <b>{</b>
                        w[i__] <font color='#5555FF'>=</font> xl[i__];
                    <b>}</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xpt[kpt <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> su[i__]<font face='Lucida Console'>)</font> <b>{</b>
                        w[i__] <font color='#5555FF'>=</font> xu[i__];
                    <b>}</b>
                    <font color='#009900'>/* L290: */</font>
                <b>}</b>
                <font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>(</font>nf<font face='Lucida Console'>)</font>;
                f <font color='#5555FF'>=</font> <font color='#BB00BB'>calfun</font><font face='Lucida Console'>(</font><font color='#BB00BB'>mat</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>w[<font color='#979000'>1</font>],n<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                fval[kpt] <font color='#5555FF'>=</font> f;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>f <font color='#5555FF'>&lt;</font> fval[kopt]<font face='Lucida Console'>)</font> <b>{</b>
                    kopt <font color='#5555FF'>=</font> kpt;
                <b>}</b>
                diff <font color='#5555FF'>=</font> f <font color='#5555FF'>-</font> vquad;

                <font color='#009900'>/*     Update the quadratic model. The RETURN from the subroutine occurs when */</font>
                <font color='#009900'>/*     all the new interpolation points are included in the model. */</font>

                i__3 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__3; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L310: */</font>
                    gopt[i__] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> diff <font color='#5555FF'>*</font> bmat[kpt <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> bmat_dim1];
                <b>}</b>
                i__3 <font color='#5555FF'>=</font> npt;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__3; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                    sum <font color='#5555FF'>=</font> zero;
                    i__2 <font color='#5555FF'>=</font> nptm;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#009900'>/* L320: */</font>
                        sum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> zmat[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1] <font color='#5555FF'>*</font> zmat[kpt <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1];
                    <b>}</b>
                    temp <font color='#5555FF'>=</font> diff <font color='#5555FF'>*</font> sum;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ptsid[k] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                        pq[k] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp;
                    <b>}</b> <font color='#0000FF'>else</font> <b>{</b>
                        ip <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>integer<font face='Lucida Console'>)</font> ptsid[k];
                        iq <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>integer<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>doublereal<font face='Lucida Console'>)</font> np <font color='#5555FF'>*</font> ptsid[k] <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font>doublereal<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>ip 
                                                                                   <font color='#5555FF'>*</font> np<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                        ihq <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>iq <font color='#5555FF'>*</font> iq <font color='#5555FF'>+</font> iq<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> <font color='#979000'>2</font>;
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ip <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                            <font color='#009900'>/* Computing 2nd power */</font>
                            d__1 <font color='#5555FF'>=</font> ptsaux[<font face='Lucida Console'>(</font>iq <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>2</font>];
                            hq[ihq] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>d__1 <font color='#5555FF'>*</font> d__1<font face='Lucida Console'>)</font>;
                        <b>}</b> <font color='#0000FF'>else</font> <b>{</b>
                            ihp <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>ip <font color='#5555FF'>*</font> ip <font color='#5555FF'>+</font> ip<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> <font color='#979000'>2</font>;
                            <font color='#009900'>/* Computing 2nd power */</font>
                            d__1 <font color='#5555FF'>=</font> ptsaux[<font face='Lucida Console'>(</font>ip <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>];
                            hq[ihp] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>d__1 <font color='#5555FF'>*</font> d__1<font face='Lucida Console'>)</font>;
                            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>iq <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                                <font color='#009900'>/* Computing 2nd power */</font>
                                d__1 <font color='#5555FF'>=</font> ptsaux[<font face='Lucida Console'>(</font>iq <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>];
                                hq[ihq] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>d__1 <font color='#5555FF'>*</font> d__1<font face='Lucida Console'>)</font>;
                                iw <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>ihp,ihq<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font>i__2 <font color='#5555FF'>=</font> iq <font color='#5555FF'>-</font> ip, std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>i__2<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                                hq[iw] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp <font color='#5555FF'>*</font> ptsaux[<font face='Lucida Console'>(</font>ip <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>] <font color='#5555FF'>*</font> ptsaux[<font face='Lucida Console'>(</font>iq <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font>
                                                                                 <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>];
                            <b>}</b>
                        <b>}</b>
                    <b>}</b>
                    <font color='#009900'>/* L330: */</font>
                <b>}</b>
                ptsid[kpt] <font color='#5555FF'>=</font> zero;
L340:
                ;
            <b>}</b>
L350:
            ;
        <b>}</b> <font color='#009900'>/* rescue_ */</font>

    <font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='trsbox_'></a>trsbox_</b><font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> integer n,
            <font color='#0000FF'>const</font> integer npt,
            <font color='#0000FF'>const</font> doublereal <font color='#5555FF'>*</font>xpt, 
            <font color='#0000FF'>const</font> doublereal <font color='#5555FF'>*</font>xopt,
            <font color='#0000FF'>const</font> doublereal <font color='#5555FF'>*</font>gopt,
            <font color='#0000FF'>const</font> doublereal <font color='#5555FF'>*</font>hq,
            <font color='#0000FF'>const</font> doublereal <font color='#5555FF'>*</font>pq, 
            <font color='#0000FF'>const</font> doublereal <font color='#5555FF'>*</font>sl,
            <font color='#0000FF'>const</font> doublereal <font color='#5555FF'>*</font>su,
            <font color='#0000FF'>const</font> doublereal delta,
            doublereal <font color='#5555FF'>*</font>xnew, 
            doublereal <font color='#5555FF'>*</font>d__,
            doublereal <font color='#5555FF'>*</font>gnew,
            doublereal <font color='#5555FF'>*</font>xbdi,
            doublereal <font color='#5555FF'>*</font>s, 
            doublereal <font color='#5555FF'>*</font>hs,
            doublereal <font color='#5555FF'>*</font>hred,
            doublereal <font color='#5555FF'>*</font>dsq,
            doublereal <font color='#5555FF'>*</font>crvmin
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            <font color='#009900'>/* System generated locals */</font>
            integer xpt_dim1, xpt_offset, i__1, i__2;
            doublereal d__1, d__2, d__3, d__4;

            <font color='#009900'>/* Local variables */</font>
            integer i__, j, k, ih;
            doublereal ds;
            integer iu;
            doublereal dhd, dhs, cth, one, shs, sth, ssq, half, beta, sdec, blen;
            integer iact <font color='#5555FF'>=</font> <font color='#979000'>0</font>, nact <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            doublereal angt, qred;
            integer isav;
            doublereal temp <font color='#5555FF'>=</font> <font color='#979000'>0</font>, zero <font color='#5555FF'>=</font> <font color='#979000'>0</font>, xsav <font color='#5555FF'>=</font> <font color='#979000'>0</font>, xsum <font color='#5555FF'>=</font> <font color='#979000'>0</font>, angbd <font color='#5555FF'>=</font> <font color='#979000'>0</font>, dredg <font color='#5555FF'>=</font> <font color='#979000'>0</font>, sredg <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            integer iterc;
            doublereal resid <font color='#5555FF'>=</font> <font color='#979000'>0</font>, delsq <font color='#5555FF'>=</font> <font color='#979000'>0</font>, ggsav <font color='#5555FF'>=</font> <font color='#979000'>0</font>, tempa <font color='#5555FF'>=</font> <font color='#979000'>0</font>, tempb <font color='#5555FF'>=</font> <font color='#979000'>0</font>,  
                       redmax <font color='#5555FF'>=</font> <font color='#979000'>0</font>, dredsq <font color='#5555FF'>=</font> <font color='#979000'>0</font>, redsav <font color='#5555FF'>=</font> <font color='#979000'>0</font>, onemin <font color='#5555FF'>=</font> <font color='#979000'>0</font>, gredsq <font color='#5555FF'>=</font> <font color='#979000'>0</font>, rednew <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            integer itcsav <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            doublereal rdprev <font color='#5555FF'>=</font> <font color='#979000'>0</font>, rdnext <font color='#5555FF'>=</font> <font color='#979000'>0</font>, stplen <font color='#5555FF'>=</font> <font color='#979000'>0</font>, stepsq <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            integer itermax <font color='#5555FF'>=</font> <font color='#979000'>0</font>;


            <font color='#009900'>/*     The arguments N, NPT, XPT, XOPT, GOPT, HQ, PQ, SL and SU have the same */</font>
            <font color='#009900'>/*       meanings as the corresponding arguments of BOBYQB. */</font>
            <font color='#009900'>/*     DELTA is the trust region radius for the present calculation, which */</font>
            <font color='#009900'>/*       seeks a small value of the quadratic model within distance DELTA of */</font>
            <font color='#009900'>/*       XOPT subject to the bounds on the variables. */</font>
            <font color='#009900'>/*     XNEW will be set to a new vector of variables that is approximately */</font>
            <font color='#009900'>/*       the one that minimizes the quadratic model within the trust region */</font>
            <font color='#009900'>/*       subject to the SL and SU constraints on the variables. It satisfies */</font>
            <font color='#009900'>/*       as equations the bounds that become active during the calculation. */</font>
            <font color='#009900'>/*     D is the calculated trial step from XOPT, generated iteratively from an */</font>
            <font color='#009900'>/*       initial value of zero. Thus XNEW is XOPT+D after the final iteration. */</font>
            <font color='#009900'>/*     GNEW holds the gradient of the quadratic model at XOPT+D. It is updated */</font>
            <font color='#009900'>/*       when D is updated. */</font>
            <font color='#009900'>/*     XBDI is a working space vector. For I=1,2,...,N, the element XBDI(I) is */</font>
            <font color='#009900'>/*       set to -1.0, 0.0, or 1.0, the value being nonzero if and only if the */</font>
            <font color='#009900'>/*       I-th variable has become fixed at a bound, the bound being SL(I) or */</font>
            <font color='#009900'>/*       SU(I) in the case XBDI(I)=-1.0 or XBDI(I)=1.0, respectively. This */</font>
            <font color='#009900'>/*       information is accumulated during the construction of XNEW. */</font>
            <font color='#009900'>/*     The arrays S, HS and HRED are also used for working space. They hold the */</font>
            <font color='#009900'>/*       current search direction, and the changes in the gradient of Q along S */</font>
            <font color='#009900'>/*       and the reduced D, respectively, where the reduced D is the same as D, */</font>
            <font color='#009900'>/*       except that the components of the fixed variables are zero. */</font>
            <font color='#009900'>/*     DSQ will be set to the square of the length of XNEW-XOPT. */</font>
            <font color='#009900'>/*     CRVMIN is set to zero if D reaches the trust region boundary. Otherwise */</font>
            <font color='#009900'>/*       it is set to the least curvature of H that occurs in the conjugate */</font>
            <font color='#009900'>/*       gradient searches that are not restricted by any constraints. The */</font>
            <font color='#009900'>/*       value CRVMIN=-1.0D0 is set, however, if all of these searches are */</font>
            <font color='#009900'>/*       constrained. */</font>

            <font color='#009900'>/*     A version of the truncated conjugate gradient is applied. If a line */</font>
            <font color='#009900'>/*     search is restricted by a constraint, then the procedure is restarted, */</font>
            <font color='#009900'>/*     the values of the variables that are at their bounds being fixed. If */</font>
            <font color='#009900'>/*     the trust region boundary is reached, then further changes may be made */</font>
            <font color='#009900'>/*     to D, each one being in the two dimensional space that is spanned */</font>
            <font color='#009900'>/*     by the current D and the gradient of Q at XOPT+D, staying on the trust */</font>
            <font color='#009900'>/*     region boundary. Termination occurs when the reduction in Q seems to */</font>
            <font color='#009900'>/*     be close to the greatest reduction that can be achieved. */</font>

            <font color='#009900'>/*     Set some constants. */</font>

            <font color='#009900'>/* Parameter adjustments */</font>
            xpt_dim1 <font color='#5555FF'>=</font> npt;
            xpt_offset <font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>+</font> xpt_dim1;
            xpt <font color='#5555FF'>-</font><font color='#5555FF'>=</font> xpt_offset;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>xopt;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>gopt;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>hq;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>pq;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>sl;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>su;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>xnew;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>d__;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>gnew;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>xbdi;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>s;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>hs;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>hred;

            <font color='#009900'>/* Function Body */</font>
            half <font color='#5555FF'>=</font> .<font color='#979000'>5</font>;
            one <font color='#5555FF'>=</font> <font color='#979000'>1.</font>;
            onemin <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1.</font>;
            zero <font color='#5555FF'>=</font> <font color='#979000'>0.</font>;

            <font color='#009900'>/*     The sign of GOPT(I) gives the sign of the change to the I-th variable */</font>
            <font color='#009900'>/*     that will reduce Q from its value at XOPT. Thus XBDI(I) shows whether */</font>
            <font color='#009900'>/*     or not to fix the I-th variable at one of its bounds initially, with */</font>
            <font color='#009900'>/*     NACT being set to the number of fixed variables. D and GNEW are also */</font>
            <font color='#009900'>/*     set for the first iteration. DELSQ is the upper bound on the sum of */</font>
            <font color='#009900'>/*     squares of the free variables. QRED is the reduction in Q so far. */</font>

            iterc <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            nact <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            i__1 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                xbdi[i__] <font color='#5555FF'>=</font> zero;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xopt[i__] <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> sl[i__]<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>gopt[i__] <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                        xbdi[i__] <font color='#5555FF'>=</font> onemin;
                    <b>}</b>
                <b>}</b> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xopt[i__] <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> su[i__]<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>gopt[i__] <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                        xbdi[i__] <font color='#5555FF'>=</font> one;
                    <b>}</b>
                <b>}</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xbdi[i__] <font color='#5555FF'>!</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#5555FF'>+</font><font color='#5555FF'>+</font>nact;
                <b>}</b>
                d__[i__] <font color='#5555FF'>=</font> zero;
                <font color='#009900'>/* L10: */</font>
                gnew[i__] <font color='#5555FF'>=</font> gopt[i__];
            <b>}</b>
            delsq <font color='#5555FF'>=</font> delta <font color='#5555FF'>*</font> delta;
            qred <font color='#5555FF'>=</font> zero;
            <font color='#5555FF'>*</font>crvmin <font color='#5555FF'>=</font> onemin;

            <font color='#009900'>/*     Set the next search direction of the conjugate gradient method. It is */</font>
            <font color='#009900'>/*     the steepest descent direction initially and when the iterations are */</font>
            <font color='#009900'>/*     restarted because a variable has just been fixed by a bound, and of */</font>
            <font color='#009900'>/*     course the components of the fixed variables are zero. ITERMAX is an */</font>
            <font color='#009900'>/*     upper bound on the indices of the conjugate gradient iterations. */</font>

L20:
            beta <font color='#5555FF'>=</font> zero;
L30:
            stepsq <font color='#5555FF'>=</font> zero;
            i__1 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xbdi[i__] <font color='#5555FF'>!</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    s[i__] <font color='#5555FF'>=</font> zero;
                <b>}</b> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>beta <font color='#5555FF'>=</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    s[i__] <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>gnew[i__];
                <b>}</b> <font color='#0000FF'>else</font> <b>{</b>
                    s[i__] <font color='#5555FF'>=</font> beta <font color='#5555FF'>*</font> s[i__] <font color='#5555FF'>-</font> gnew[i__];
                <b>}</b>
                <font color='#009900'>/* L40: */</font>
                <font color='#009900'>/* Computing 2nd power */</font>
                d__1 <font color='#5555FF'>=</font> s[i__];
                stepsq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>stepsq <font color='#5555FF'>=</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>goto</font> L190;
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>beta <font color='#5555FF'>=</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                gredsq <font color='#5555FF'>=</font> stepsq;
                itermax <font color='#5555FF'>=</font> iterc <font color='#5555FF'>+</font> n <font color='#5555FF'>-</font> nact;
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>gredsq <font color='#5555FF'>*</font> delsq <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> qred <font color='#5555FF'>*</font> <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>4</font> <font color='#5555FF'>*</font> qred<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>goto</font> L190;
            <b>}</b>

            <font color='#009900'>/*     Multiply the search direction by the second derivative matrix of Q and */</font>
            <font color='#009900'>/*     calculate some scalars for the choice of steplength. Then set BLEN to */</font>
            <font color='#009900'>/*     the length of the the step to the trust region boundary and STPLEN to */</font>
            <font color='#009900'>/*     the steplength, ignoring the simple bounds. */</font>

            <font color='#0000FF'>goto</font> L210;
L50:
            resid <font color='#5555FF'>=</font> delsq;
            ds <font color='#5555FF'>=</font> zero;
            shs <font color='#5555FF'>=</font> zero;
            i__1 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xbdi[i__] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* Computing 2nd power */</font>
                    d__1 <font color='#5555FF'>=</font> d__[i__];
                    resid <font color='#5555FF'>-</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                    ds <font color='#5555FF'>+</font><font color='#5555FF'>=</font> s[i__] <font color='#5555FF'>*</font> d__[i__];
                    shs <font color='#5555FF'>+</font><font color='#5555FF'>=</font> s[i__] <font color='#5555FF'>*</font> hs[i__];
                <b>}</b>
                <font color='#009900'>/* L60: */</font>
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>resid <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>goto</font> L90;
            <b>}</b>
            temp <font color='#5555FF'>=</font> std::<font color='#BB00BB'>sqrt</font><font face='Lucida Console'>(</font>stepsq <font color='#5555FF'>*</font> resid <font color='#5555FF'>+</font> ds <font color='#5555FF'>*</font> ds<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ds <font color='#5555FF'>&lt;</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                blen <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>temp <font color='#5555FF'>-</font> ds<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> stepsq;
            <b>}</b> <font color='#0000FF'>else</font> <b>{</b>
                blen <font color='#5555FF'>=</font> resid <font color='#5555FF'>/</font> <font face='Lucida Console'>(</font>temp <font color='#5555FF'>+</font> ds<font face='Lucida Console'>)</font>;
            <b>}</b>
            stplen <font color='#5555FF'>=</font> blen;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>shs <font color='#5555FF'>&gt;</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#009900'>/* Computing MIN */</font>
                d__1 <font color='#5555FF'>=</font> blen, d__2 <font color='#5555FF'>=</font> gredsq <font color='#5555FF'>/</font> shs;
                stplen <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
            <b>}</b>

            <font color='#009900'>/*     Reduce STPLEN if necessary in order to preserve the simple bounds, */</font>
            <font color='#009900'>/*     letting IACT be the index of the new constrained variable. */</font>

            iact <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            i__1 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>s[i__] <font color='#5555FF'>!</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    xsum <font color='#5555FF'>=</font> xopt[i__] <font color='#5555FF'>+</font> d__[i__];
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>s[i__] <font color='#5555FF'>&gt;</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                        temp <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>su[i__] <font color='#5555FF'>-</font> xsum<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> s[i__];
                    <b>}</b> <font color='#0000FF'>else</font> <b>{</b>
                        temp <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>sl[i__] <font color='#5555FF'>-</font> xsum<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> s[i__];
                    <b>}</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp <font color='#5555FF'>&lt;</font> stplen<font face='Lucida Console'>)</font> <b>{</b>
                        stplen <font color='#5555FF'>=</font> temp;
                        iact <font color='#5555FF'>=</font> i__;
                    <b>}</b>
                <b>}</b>
                <font color='#009900'>/* L70: */</font>
            <b>}</b>

            <font color='#009900'>/*     Update CRVMIN, GNEW and D. Set SDEC to the decrease that occurs in Q. */</font>

            sdec <font color='#5555FF'>=</font> zero;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>stplen <font color='#5555FF'>&gt;</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#5555FF'>+</font><font color='#5555FF'>+</font>iterc;
                temp <font color='#5555FF'>=</font> shs <font color='#5555FF'>/</font> stepsq;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>iact <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> temp <font color='#5555FF'>&gt;</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#5555FF'>*</font>crvmin <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>crvmin,temp<font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>crvmin <font color='#5555FF'>=</font><font color='#5555FF'>=</font> onemin<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#5555FF'>*</font>crvmin <font color='#5555FF'>=</font> temp;
                    <b>}</b>
                <b>}</b>
                ggsav <font color='#5555FF'>=</font> gredsq;
                gredsq <font color='#5555FF'>=</font> zero;
                i__1 <font color='#5555FF'>=</font> n;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                    gnew[i__] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> stplen <font color='#5555FF'>*</font> hs[i__];
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xbdi[i__] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#009900'>/* Computing 2nd power */</font>
                        d__1 <font color='#5555FF'>=</font> gnew[i__];
                        gredsq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                    <b>}</b>
                    <font color='#009900'>/* L80: */</font>
                    d__[i__] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> stplen <font color='#5555FF'>*</font> s[i__];
                <b>}</b>
                <font color='#009900'>/* Computing MAX */</font>
                d__1 <font color='#5555FF'>=</font> stplen <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>ggsav <font color='#5555FF'>-</font> half <font color='#5555FF'>*</font> stplen <font color='#5555FF'>*</font> shs<font face='Lucida Console'>)</font>;
                sdec <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__1,zero<font face='Lucida Console'>)</font>;
                qred <font color='#5555FF'>+</font><font color='#5555FF'>=</font> sdec;
            <b>}</b>

            <font color='#009900'>/*     Restart the conjugate gradient method if it has hit a new bound. */</font>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>iact <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                <font color='#5555FF'>+</font><font color='#5555FF'>+</font>nact;
                xbdi[iact] <font color='#5555FF'>=</font> one;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>s[iact] <font color='#5555FF'>&lt;</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    xbdi[iact] <font color='#5555FF'>=</font> onemin;
                <b>}</b>
                <font color='#009900'>/* Computing 2nd power */</font>
                d__1 <font color='#5555FF'>=</font> d__[iact];
                delsq <font color='#5555FF'>-</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>delsq <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#0000FF'>goto</font> L90;
                <b>}</b>
                <font color='#0000FF'>goto</font> L20;
            <b>}</b>

            <font color='#009900'>/*     If STPLEN is less than BLEN, then either apply another conjugate */</font>
            <font color='#009900'>/*     gradient iteration or RETURN. */</font>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>stplen <font color='#5555FF'>&lt;</font> blen<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>iterc <font color='#5555FF'>=</font><font color='#5555FF'>=</font> itermax<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#0000FF'>goto</font> L190;
                <b>}</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>sdec <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> qred <font color='#5555FF'>*</font> .<font color='#979000'>01</font><font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#0000FF'>goto</font> L190;
                <b>}</b>
                beta <font color='#5555FF'>=</font> gredsq <font color='#5555FF'>/</font> ggsav;
                <font color='#0000FF'>goto</font> L30;
            <b>}</b>
L90:
            <font color='#5555FF'>*</font>crvmin <font color='#5555FF'>=</font> zero;

            <font color='#009900'>/*     Prepare for the alternative iteration by calculating some scalars */</font>
            <font color='#009900'>/*     and by multiplying the reduced D by the second derivative matrix of */</font>
            <font color='#009900'>/*     Q, where S holds the reduced D in the call of GGMULT. */</font>

L100:
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>nact <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> n <font color='#5555FF'>-</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>goto</font> L190;
            <b>}</b>
            dredsq <font color='#5555FF'>=</font> zero;
            dredg <font color='#5555FF'>=</font> zero;
            gredsq <font color='#5555FF'>=</font> zero;
            i__1 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xbdi[i__] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* Computing 2nd power */</font>
                    d__1 <font color='#5555FF'>=</font> d__[i__];
                    dredsq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                    dredg <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__[i__] <font color='#5555FF'>*</font> gnew[i__];
                    <font color='#009900'>/* Computing 2nd power */</font>
                    d__1 <font color='#5555FF'>=</font> gnew[i__];
                    gredsq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                    s[i__] <font color='#5555FF'>=</font> d__[i__];
                <b>}</b> <font color='#0000FF'>else</font> <b>{</b>
                    s[i__] <font color='#5555FF'>=</font> zero;
                <b>}</b>
                <font color='#009900'>/* L110: */</font>
            <b>}</b>
            itcsav <font color='#5555FF'>=</font> iterc;
            <font color='#0000FF'>goto</font> L210;

            <font color='#009900'>/*     Let the search direction S be a linear combination of the reduced D */</font>
            <font color='#009900'>/*     and the reduced G that is orthogonal to the reduced D. */</font>

L120:
            <font color='#5555FF'>+</font><font color='#5555FF'>+</font>iterc;
            temp <font color='#5555FF'>=</font> gredsq <font color='#5555FF'>*</font> dredsq <font color='#5555FF'>-</font> dredg <font color='#5555FF'>*</font> dredg;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> qred <font color='#5555FF'>*</font> <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>4</font> <font color='#5555FF'>*</font> qred<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>goto</font> L190;
            <b>}</b>
            temp <font color='#5555FF'>=</font> std::<font color='#BB00BB'>sqrt</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
            i__1 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xbdi[i__] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    s[i__] <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>dredg <font color='#5555FF'>*</font> d__[i__] <font color='#5555FF'>-</font> dredsq <font color='#5555FF'>*</font> gnew[i__]<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> temp;
                <b>}</b> <font color='#0000FF'>else</font> <b>{</b>
                    s[i__] <font color='#5555FF'>=</font> zero;
                <b>}</b>
                <font color='#009900'>/* L130: */</font>
            <b>}</b>
            sredg <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>temp;

            <font color='#009900'>/*     By considering the simple bounds on the variables, calculate an upper */</font>
            <font color='#009900'>/*     bound on the tangent of half the angle of the alternative iteration, */</font>
            <font color='#009900'>/*     namely ANGBD, except that, if already a free variable has reached a */</font>
            <font color='#009900'>/*     bound, there is a branch back to label 100 after fixing that variable. */</font>

            angbd <font color='#5555FF'>=</font> one;
            iact <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            i__1 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xbdi[i__] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    tempa <font color='#5555FF'>=</font> xopt[i__] <font color='#5555FF'>+</font> d__[i__] <font color='#5555FF'>-</font> sl[i__];
                    tempb <font color='#5555FF'>=</font> su[i__] <font color='#5555FF'>-</font> xopt[i__] <font color='#5555FF'>-</font> d__[i__];
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>tempa <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#5555FF'>+</font><font color='#5555FF'>+</font>nact;
                        xbdi[i__] <font color='#5555FF'>=</font> onemin;
                        <font color='#0000FF'>goto</font> L100;
                    <b>}</b> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>tempb <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#5555FF'>+</font><font color='#5555FF'>+</font>nact;
                        xbdi[i__] <font color='#5555FF'>=</font> one;
                        <font color='#0000FF'>goto</font> L100;
                    <b>}</b>
                    <font color='#009900'>/* Computing 2nd power */</font>
                    d__1 <font color='#5555FF'>=</font> d__[i__];
                    <font color='#009900'>/* Computing 2nd power */</font>
                    d__2 <font color='#5555FF'>=</font> s[i__];
                    ssq <font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1 <font color='#5555FF'>+</font> d__2 <font color='#5555FF'>*</font> d__2;
                    <font color='#009900'>/* Computing 2nd power */</font>
                    d__1 <font color='#5555FF'>=</font> xopt[i__] <font color='#5555FF'>-</font> sl[i__];
                    temp <font color='#5555FF'>=</font> ssq <font color='#5555FF'>-</font> d__1 <font color='#5555FF'>*</font> d__1;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp <font color='#5555FF'>&gt;</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                        temp <font color='#5555FF'>=</font> std::<font color='#BB00BB'>sqrt</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> s[i__];
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>angbd <font color='#5555FF'>*</font> temp <font color='#5555FF'>&gt;</font> tempa<font face='Lucida Console'>)</font> <b>{</b>
                            angbd <font color='#5555FF'>=</font> tempa <font color='#5555FF'>/</font> temp;
                            iact <font color='#5555FF'>=</font> i__;
                            xsav <font color='#5555FF'>=</font> onemin;
                        <b>}</b>
                    <b>}</b>
                    <font color='#009900'>/* Computing 2nd power */</font>
                    d__1 <font color='#5555FF'>=</font> su[i__] <font color='#5555FF'>-</font> xopt[i__];
                    temp <font color='#5555FF'>=</font> ssq <font color='#5555FF'>-</font> d__1 <font color='#5555FF'>*</font> d__1;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp <font color='#5555FF'>&gt;</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                        temp <font color='#5555FF'>=</font> std::<font color='#BB00BB'>sqrt</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> s[i__];
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>angbd <font color='#5555FF'>*</font> temp <font color='#5555FF'>&gt;</font> tempb<font face='Lucida Console'>)</font> <b>{</b>
                            angbd <font color='#5555FF'>=</font> tempb <font color='#5555FF'>/</font> temp;
                            iact <font color='#5555FF'>=</font> i__;
                            xsav <font color='#5555FF'>=</font> one;
                        <b>}</b>
                    <b>}</b>
                <b>}</b>
                <font color='#009900'>/* L140: */</font>
            <b>}</b>

            <font color='#009900'>/*     Calculate HHD and some curvatures for the alternative iteration. */</font>

            <font color='#0000FF'>goto</font> L210;
L150:
            shs <font color='#5555FF'>=</font> zero;
            dhs <font color='#5555FF'>=</font> zero;
            dhd <font color='#5555FF'>=</font> zero;
            i__1 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xbdi[i__] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    shs <font color='#5555FF'>+</font><font color='#5555FF'>=</font> s[i__] <font color='#5555FF'>*</font> hs[i__];
                    dhs <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__[i__] <font color='#5555FF'>*</font> hs[i__];
                    dhd <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__[i__] <font color='#5555FF'>*</font> hred[i__];
                <b>}</b>
                <font color='#009900'>/* L160: */</font>
            <b>}</b>

            <font color='#009900'>/*     Seek the greatest reduction in Q for a range of equally spaced values */</font>
            <font color='#009900'>/*     of ANGT in [0,ANGBD], where ANGT is the tangent of half the angle of */</font>
            <font color='#009900'>/*     the alternative iteration. */</font>

            redmax <font color='#5555FF'>=</font> zero;
            isav <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            redsav <font color='#5555FF'>=</font> zero;
            iu <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>integer<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>angbd <font color='#5555FF'>*</font> <font color='#979000'>17.</font> <font color='#5555FF'>+</font> <font color='#979000'>3.1</font><font face='Lucida Console'>)</font>;
            i__1 <font color='#5555FF'>=</font> iu;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                angt <font color='#5555FF'>=</font> angbd <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>doublereal<font face='Lucida Console'>)</font> i__ <font color='#5555FF'>/</font> <font face='Lucida Console'>(</font>doublereal<font face='Lucida Console'>)</font> iu;
                sth <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>angt <font color='#5555FF'>+</font> angt<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> <font face='Lucida Console'>(</font>one <font color='#5555FF'>+</font> angt <font color='#5555FF'>*</font> angt<font face='Lucida Console'>)</font>;
                temp <font color='#5555FF'>=</font> shs <font color='#5555FF'>+</font> angt <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>angt <font color='#5555FF'>*</font> dhd <font color='#5555FF'>-</font> dhs <font color='#5555FF'>-</font> dhs<font face='Lucida Console'>)</font>;
                rednew <font color='#5555FF'>=</font> sth <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>angt <font color='#5555FF'>*</font> dredg <font color='#5555FF'>-</font> sredg <font color='#5555FF'>-</font> half <font color='#5555FF'>*</font> sth <font color='#5555FF'>*</font> temp<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rednew <font color='#5555FF'>&gt;</font> redmax<font face='Lucida Console'>)</font> <b>{</b>
                    redmax <font color='#5555FF'>=</font> rednew;
                    isav <font color='#5555FF'>=</font> i__;
                    rdprev <font color='#5555FF'>=</font> redsav;
                <b>}</b> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font><font color='#5555FF'>=</font> isav <font color='#5555FF'>+</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <b>{</b>
                    rdnext <font color='#5555FF'>=</font> rednew;
                <b>}</b>
                <font color='#009900'>/* L170: */</font>
                redsav <font color='#5555FF'>=</font> rednew;
            <b>}</b>

            <font color='#009900'>/*     Return if the reduction is zero. Otherwise, set the sine and cosine */</font>
            <font color='#009900'>/*     of the angle of the alternative iteration, and calculate SDEC. */</font>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>isav <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>goto</font> L190;
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>isav <font color='#5555FF'>&lt;</font> iu<font face='Lucida Console'>)</font> <b>{</b>
                temp <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>rdnext <font color='#5555FF'>-</font> rdprev<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> <font face='Lucida Console'>(</font>redmax <font color='#5555FF'>+</font> redmax <font color='#5555FF'>-</font> rdprev <font color='#5555FF'>-</font> rdnext<font face='Lucida Console'>)</font>;
                angt <font color='#5555FF'>=</font> angbd <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>doublereal<font face='Lucida Console'>)</font> isav <font color='#5555FF'>+</font> half <font color='#5555FF'>*</font> temp<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> <font face='Lucida Console'>(</font>doublereal<font face='Lucida Console'>)</font> iu;
            <b>}</b>
            cth <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>one <font color='#5555FF'>-</font> angt <font color='#5555FF'>*</font> angt<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> <font face='Lucida Console'>(</font>one <font color='#5555FF'>+</font> angt <font color='#5555FF'>*</font> angt<font face='Lucida Console'>)</font>;
            sth <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>angt <font color='#5555FF'>+</font> angt<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> <font face='Lucida Console'>(</font>one <font color='#5555FF'>+</font> angt <font color='#5555FF'>*</font> angt<font face='Lucida Console'>)</font>;
            temp <font color='#5555FF'>=</font> shs <font color='#5555FF'>+</font> angt <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>angt <font color='#5555FF'>*</font> dhd <font color='#5555FF'>-</font> dhs <font color='#5555FF'>-</font> dhs<font face='Lucida Console'>)</font>;
            sdec <font color='#5555FF'>=</font> sth <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>angt <font color='#5555FF'>*</font> dredg <font color='#5555FF'>-</font> sredg <font color='#5555FF'>-</font> half <font color='#5555FF'>*</font> sth <font color='#5555FF'>*</font> temp<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>sdec <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>goto</font> L190;
            <b>}</b>

            <font color='#009900'>/*     Update GNEW, D and HRED. If the angle of the alternative iteration */</font>
            <font color='#009900'>/*     is restricted by a bound on a free variable, that variable is fixed */</font>
            <font color='#009900'>/*     at the bound. */</font>

            dredg <font color='#5555FF'>=</font> zero;
            gredsq <font color='#5555FF'>=</font> zero;
            i__1 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                gnew[i__] <font color='#5555FF'>=</font> gnew[i__] <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font>cth <font color='#5555FF'>-</font> one<font face='Lucida Console'>)</font> <font color='#5555FF'>*</font> hred[i__] <font color='#5555FF'>+</font> sth <font color='#5555FF'>*</font> hs[i__];
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xbdi[i__] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    d__[i__] <font color='#5555FF'>=</font> cth <font color='#5555FF'>*</font> d__[i__] <font color='#5555FF'>+</font> sth <font color='#5555FF'>*</font> s[i__];
                    dredg <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__[i__] <font color='#5555FF'>*</font> gnew[i__];
                    <font color='#009900'>/* Computing 2nd power */</font>
                    d__1 <font color='#5555FF'>=</font> gnew[i__];
                    gredsq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
                <b>}</b>
                <font color='#009900'>/* L180: */</font>
                hred[i__] <font color='#5555FF'>=</font> cth <font color='#5555FF'>*</font> hred[i__] <font color='#5555FF'>+</font> sth <font color='#5555FF'>*</font> hs[i__];
            <b>}</b>
            qred <font color='#5555FF'>+</font><font color='#5555FF'>=</font> sdec;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>iact <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> isav <font color='#5555FF'>=</font><font color='#5555FF'>=</font> iu<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#5555FF'>+</font><font color='#5555FF'>+</font>nact;
                xbdi[iact] <font color='#5555FF'>=</font> xsav;
                <font color='#0000FF'>goto</font> L100;
            <b>}</b>

            <font color='#009900'>/*     If SDEC is sufficiently small, then RETURN after setting XNEW to */</font>
            <font color='#009900'>/*     XOPT+D, giving careful attention to the bounds. */</font>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>sdec <font color='#5555FF'>&gt;</font> qred <font color='#5555FF'>*</font> .<font color='#979000'>01</font><font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>goto</font> L120;
            <b>}</b>
L190:
            <font color='#5555FF'>*</font>dsq <font color='#5555FF'>=</font> zero;
            i__1 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#009900'>/* Computing MAX */</font>
                <font color='#009900'>/* Computing MIN */</font>
                d__3 <font color='#5555FF'>=</font> xopt[i__] <font color='#5555FF'>+</font> d__[i__], d__4 <font color='#5555FF'>=</font> su[i__];
                d__1 <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>d__3,d__4<font face='Lucida Console'>)</font>, d__2 <font color='#5555FF'>=</font> sl[i__];
                xnew[i__] <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__1,d__2<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xbdi[i__] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> onemin<font face='Lucida Console'>)</font> <b>{</b>
                    xnew[i__] <font color='#5555FF'>=</font> sl[i__];
                <b>}</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>xbdi[i__] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> one<font face='Lucida Console'>)</font> <b>{</b>
                    xnew[i__] <font color='#5555FF'>=</font> su[i__];
                <b>}</b>
                d__[i__] <font color='#5555FF'>=</font> xnew[i__] <font color='#5555FF'>-</font> xopt[i__];
                <font color='#009900'>/* L200: */</font>
                <font color='#009900'>/* Computing 2nd power */</font>
                d__1 <font color='#5555FF'>=</font> d__[i__];
                <font color='#5555FF'>*</font>dsq <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d__1 <font color='#5555FF'>*</font> d__1;
            <b>}</b>
            <font color='#0000FF'>return</font>;
            <font color='#009900'>/*     The following instructions multiply the current S-vector by the second */</font>
            <font color='#009900'>/*     derivative matrix of the quadratic model, putting the product in HS. */</font>
            <font color='#009900'>/*     They are reached from three different parts of the software above and */</font>
            <font color='#009900'>/*     they can be regarded as an external subroutine. */</font>

L210:
            ih <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            i__1 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                hs[j] <font color='#5555FF'>=</font> zero;
                i__2 <font color='#5555FF'>=</font> j;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#5555FF'>+</font><font color='#5555FF'>+</font>ih;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>&lt;</font> j<font face='Lucida Console'>)</font> <b>{</b>
                        hs[j] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> hq[ih] <font color='#5555FF'>*</font> s[i__];
                    <b>}</b>
                    <font color='#009900'>/* L220: */</font>
                    hs[i__] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> hq[ih] <font color='#5555FF'>*</font> s[j];
                <b>}</b>
            <b>}</b>
            i__2 <font color='#5555FF'>=</font> npt;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pq[k] <font color='#5555FF'>!</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                    temp <font color='#5555FF'>=</font> zero;
                    i__1 <font color='#5555FF'>=</font> n;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#009900'>/* L230: */</font>
                        temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> xpt[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> xpt_dim1] <font color='#5555FF'>*</font> s[j];
                    <b>}</b>
                    temp <font color='#5555FF'>*</font><font color='#5555FF'>=</font> pq[k];
                    i__1 <font color='#5555FF'>=</font> n;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#009900'>/* L240: */</font>
                        hs[i__] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp <font color='#5555FF'>*</font> xpt[k <font color='#5555FF'>+</font> i__ <font color='#5555FF'>*</font> xpt_dim1];
                    <b>}</b>
                <b>}</b>
                <font color='#009900'>/* L250: */</font>
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>crvmin <font color='#5555FF'>!</font><font color='#5555FF'>=</font> zero<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>goto</font> L50;
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>iterc <font color='#5555FF'>&gt;</font> itcsav<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>goto</font> L150;
            <b>}</b>
            i__2 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#009900'>/* L260: */</font>
                hred[i__] <font color='#5555FF'>=</font> hs[i__];
            <b>}</b>
            <font color='#0000FF'>goto</font> L120;
        <b>}</b> <font color='#009900'>/* trsbox_ */</font>

    <font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='update_'></a>update_</b><font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> integer n,
            <font color='#0000FF'>const</font> integer npt,
            doublereal <font color='#5555FF'>*</font>bmat, 
            doublereal <font color='#5555FF'>*</font>zmat,
            <font color='#0000FF'>const</font> integer ndim,
            doublereal <font color='#5555FF'>*</font>vlag,
            <font color='#0000FF'>const</font> doublereal beta, 
            <font color='#0000FF'>const</font> doublereal denom,
            <font color='#0000FF'>const</font> integer knew,
            doublereal <font color='#5555FF'>*</font>w
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            <font color='#009900'>/* System generated locals */</font>
            integer bmat_dim1, bmat_offset, zmat_dim1, zmat_offset, i__1, i__2;
            doublereal d__1, d__2, d__3;

            <font color='#009900'>/* Local variables */</font>
            integer i__, j, k, jp;
            doublereal one, tau, temp;
            integer nptm;
            doublereal zero, alpha, tempa, tempb, ztest;


            <font color='#009900'>/*     The arrays BMAT and ZMAT are updated, as required by the new position */</font>
            <font color='#009900'>/*     of the interpolation point that has the index KNEW. The vector VLAG has */</font>
            <font color='#009900'>/*     N+NPT components, set on entry to the first NPT and last N components */</font>
            <font color='#009900'>/*     of the product Hw in equation (4.11) of the Powell (2006) paper on */</font>
            <font color='#009900'>/*     NEWUOA. Further, BETA is set on entry to the value of the parameter */</font>
            <font color='#009900'>/*     with that name, and DENOM is set to the denominator of the updating */</font>
            <font color='#009900'>/*     formula. Elements of ZMAT may be treated as zero if their moduli are */</font>
            <font color='#009900'>/*     at most ZTEST. The first NDIM elements of W are used for working space. */</font>

            <font color='#009900'>/*     Set some constants. */</font>

            <font color='#009900'>/* Parameter adjustments */</font>
            zmat_dim1 <font color='#5555FF'>=</font> npt;
            zmat_offset <font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>+</font> zmat_dim1;
            zmat <font color='#5555FF'>-</font><font color='#5555FF'>=</font> zmat_offset;
            bmat_dim1 <font color='#5555FF'>=</font> ndim;
            bmat_offset <font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>+</font> bmat_dim1;
            bmat <font color='#5555FF'>-</font><font color='#5555FF'>=</font> bmat_offset;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>vlag;
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>w;

            <font color='#009900'>/* Function Body */</font>
            one <font color='#5555FF'>=</font> <font color='#979000'>1.</font>;
            zero <font color='#5555FF'>=</font> <font color='#979000'>0.</font>;
            nptm <font color='#5555FF'>=</font> npt <font color='#5555FF'>-</font> n <font color='#5555FF'>-</font> <font color='#979000'>1</font>;
            ztest <font color='#5555FF'>=</font> zero;
            i__1 <font color='#5555FF'>=</font> npt;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>k <font color='#5555FF'>=</font> <font color='#979000'>1</font>; k <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> <b>{</b>
                i__2 <font color='#5555FF'>=</font> nptm;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* L10: */</font>
                    <font color='#009900'>/* Computing MAX */</font>
                    d__2 <font color='#5555FF'>=</font> ztest, d__3 <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>d__1 <font color='#5555FF'>=</font> zmat[k <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1], std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>d__1<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    ztest <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>d__2,d__3<font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
            ztest <font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>20</font>;

            <font color='#009900'>/*     Apply the rotations that put zeros in the KNEW-th row of ZMAT. */</font>

            i__2 <font color='#5555FF'>=</font> nptm;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>2</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>d__1 <font color='#5555FF'>=</font> zmat[knew <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1], std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>d__1<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> ztest<font face='Lucida Console'>)</font> <b>{</b>
                    <font color='#009900'>/* Computing 2nd power */</font>
                    d__1 <font color='#5555FF'>=</font> zmat[knew <font color='#5555FF'>+</font> zmat_dim1];
                    <font color='#009900'>/* Computing 2nd power */</font>
                    d__2 <font color='#5555FF'>=</font> zmat[knew <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1];
                    temp <font color='#5555FF'>=</font> std::<font color='#BB00BB'>sqrt</font><font face='Lucida Console'>(</font>d__1 <font color='#5555FF'>*</font> d__1 <font color='#5555FF'>+</font> d__2 <font color='#5555FF'>*</font> d__2<font face='Lucida Console'>)</font>;
                    tempa <font color='#5555FF'>=</font> zmat[knew <font color='#5555FF'>+</font> zmat_dim1] <font color='#5555FF'>/</font> temp;
                    tempb <font color='#5555FF'>=</font> zmat[knew <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1] <font color='#5555FF'>/</font> temp;
                    i__1 <font color='#5555FF'>=</font> npt;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                        temp <font color='#5555FF'>=</font> tempa <font color='#5555FF'>*</font> zmat[i__ <font color='#5555FF'>+</font> zmat_dim1] <font color='#5555FF'>+</font> tempb <font color='#5555FF'>*</font> zmat[i__ <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> 
                            zmat_dim1];
                        zmat[i__ <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1] <font color='#5555FF'>=</font> tempa <font color='#5555FF'>*</font> zmat[i__ <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1] 
                            <font color='#5555FF'>-</font> tempb <font color='#5555FF'>*</font> zmat[i__ <font color='#5555FF'>+</font> zmat_dim1];
                        <font color='#009900'>/* L20: */</font>
                        zmat[i__ <font color='#5555FF'>+</font> zmat_dim1] <font color='#5555FF'>=</font> temp;
                    <b>}</b>
                <b>}</b>
                zmat[knew <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> zmat_dim1] <font color='#5555FF'>=</font> zero;
                <font color='#009900'>/* L30: */</font>
            <b>}</b>

            <font color='#009900'>/*     Put the first NPT components of the KNEW-th column of HLAG into W, */</font>
            <font color='#009900'>/*     and calculate the parameters of the updating formula. */</font>

            i__2 <font color='#5555FF'>=</font> npt;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                w[i__] <font color='#5555FF'>=</font> zmat[knew <font color='#5555FF'>+</font> zmat_dim1] <font color='#5555FF'>*</font> zmat[i__ <font color='#5555FF'>+</font> zmat_dim1];
                <font color='#009900'>/* L40: */</font>
            <b>}</b>
            alpha <font color='#5555FF'>=</font> w[knew];
            tau <font color='#5555FF'>=</font> vlag[knew];
            vlag[knew] <font color='#5555FF'>-</font><font color='#5555FF'>=</font> one;

            <font color='#009900'>/*     Complete the updating of ZMAT. */</font>

            temp <font color='#5555FF'>=</font> std::<font color='#BB00BB'>sqrt</font><font face='Lucida Console'>(</font>denom<font face='Lucida Console'>)</font>;
            tempb <font color='#5555FF'>=</font> zmat[knew <font color='#5555FF'>+</font> zmat_dim1] <font color='#5555FF'>/</font> temp;
            tempa <font color='#5555FF'>=</font> tau <font color='#5555FF'>/</font> temp;
            i__2 <font color='#5555FF'>=</font> npt;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                <font color='#009900'>/* L50: */</font>
                zmat[i__ <font color='#5555FF'>+</font> zmat_dim1] <font color='#5555FF'>=</font> tempa <font color='#5555FF'>*</font> zmat[i__ <font color='#5555FF'>+</font> zmat_dim1] <font color='#5555FF'>-</font> tempb <font color='#5555FF'>*</font> vlag[
                    i__];
            <b>}</b>

            <font color='#009900'>/*     Finally, update the matrix BMAT. */</font>

            i__2 <font color='#5555FF'>=</font> n;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>1</font>; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                jp <font color='#5555FF'>=</font> npt <font color='#5555FF'>+</font> j;
                w[jp] <font color='#5555FF'>=</font> bmat[knew <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1];
                tempa <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>alpha <font color='#5555FF'>*</font> vlag[jp] <font color='#5555FF'>-</font> tau <font color='#5555FF'>*</font> w[jp]<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> denom;
                tempb <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#5555FF'>-</font><font face='Lucida Console'>(</font>beta<font face='Lucida Console'>)</font> <font color='#5555FF'>*</font> w[jp] <font color='#5555FF'>-</font> tau <font color='#5555FF'>*</font> vlag[jp]<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> denom;
                i__1 <font color='#5555FF'>=</font> jp;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i__ <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> i__1; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i__<font face='Lucida Console'>)</font> <b>{</b>
                    bmat[i__ <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>=</font> bmat[i__ <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>+</font> tempa <font color='#5555FF'>*</font> 
                        vlag[i__] <font color='#5555FF'>+</font> tempb <font color='#5555FF'>*</font> w[i__];
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>&gt;</font> npt<font face='Lucida Console'>)</font> <b>{</b>
                        bmat[jp <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font>i__ <font color='#5555FF'>-</font> npt<font face='Lucida Console'>)</font> <font color='#5555FF'>*</font> bmat_dim1] <font color='#5555FF'>=</font> bmat[i__ <font color='#5555FF'>+</font> j <font color='#5555FF'>*</font> 
                            bmat_dim1];
                    <b>}</b>
                    <font color='#009900'>/* L60: */</font>
                <b>}</b>
            <b>}</b>
        <b>}</b> <font color='#009900'>/* update_ */</font>
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> funct,
        <font color='#0000FF'>typename</font> T, 
        <font color='#0000FF'>typename</font> U
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>double</u></font> <b><a name='find_min_bobyqa'></a>find_min_bobyqa</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> funct<font color='#5555FF'>&amp;</font> f,
        T<font color='#5555FF'>&amp;</font> x,
        <font color='#0000FF'><u>long</u></font> npt,
        <font color='#0000FF'>const</font> U<font color='#5555FF'>&amp;</font> x_lower,
        <font color='#0000FF'>const</font> U<font color='#5555FF'>&amp;</font> x_upper,
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> rho_begin,
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> rho_end,
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> max_f_evals
    <font face='Lucida Console'>)</font> 
    <b>{</b>
        <font color='#009900'>// The starting point (i.e. x) must be a column vector.  
</font>        <font color='#BB00BB'>COMPILE_TIME_ASSERT</font><font face='Lucida Console'>(</font>T::NC <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// check the requirements.  Also split the assert up so that the error message isn't huge.
</font>        <font color='#BB00BB'>DLIB_CASSERT</font><font face='Lucida Console'>(</font><font color='#BB00BB'>is_col_vector</font><font face='Lucida Console'>(</font>x<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#BB00BB'>is_col_vector</font><font face='Lucida Console'>(</font>x_lower<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#BB00BB'>is_col_vector</font><font face='Lucida Console'>(</font>x_upper<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                    x.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> x_lower.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> x_lower.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> x_upper.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                    x.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> <font color='#979000'>1</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> max_f_evals <font color='#5555FF'>&gt;</font> <font color='#979000'>1</font>,
            "<font color='#CC0000'>\tdouble find_min_bobyqa()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid arguments have been given to this function</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_col_vector(x):       </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_col_vector</font><font face='Lucida Console'>(</font>x<font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_col_vector(x_lower): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_col_vector</font><font face='Lucida Console'>(</font>x_lower<font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_col_vector(x_upper): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_col_vector</font><font face='Lucida Console'>(</font>x_upper<font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t x.size():               </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> x.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t x_lower.size():         </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> x_lower.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t x_upper.size():         </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> x_upper.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t max_f_evals:            </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> max_f_evals
        <font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>DLIB_CASSERT</font><font face='Lucida Console'>(</font>x.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>2</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> npt <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> npt <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>x.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font>x.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>2</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                    <font color='#979000'>0</font> <font color='#5555FF'>&lt;</font> rho_end <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> rho_end <font color='#5555FF'>&lt;</font> rho_begin <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                    <font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>x_upper <font color='#5555FF'>-</font> x_lower<font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> <font color='#979000'>2</font><font color='#5555FF'>*</font>rho_begin <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                    <font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>x <font color='#5555FF'>-</font> x_lower<font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>x_upper <font color='#5555FF'>-</font> x<font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> <font color='#979000'>0</font>,
            "<font color='#CC0000'>\tdouble find_min_bobyqa()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid arguments have been given to this function</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t ntp in valid range: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font face='Lucida Console'>(</font>x.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>2</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> npt <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> npt <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>x.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font>x.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>2</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t npt:                </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> npt 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t rho_begin:          </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> rho_begin 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t rho_end:            </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> rho_end
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t min(x_upper - x_lower) &gt; 2*rho_begin:           </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>x_upper <font color='#5555FF'>-</font> x_lower<font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> <font color='#979000'>2</font><font color='#5555FF'>*</font>rho_begin<font face='Lucida Console'>)</font>
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t min(x - x_lower) &gt;= 0 &amp;&amp; min(x_upper - x) &gt;= 0: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>x <font color='#5555FF'>-</font> x_lower<font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>x_upper <font color='#5555FF'>-</font> x<font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
        <font face='Lucida Console'>)</font>;


        bobyqa_implementation impl;
        <font color='#0000FF'>return</font> impl.<font color='#BB00BB'>find_min</font><font face='Lucida Console'>(</font>f, x, npt, x_lower, x_upper, rho_begin, rho_end, max_f_evals<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> funct,
        <font color='#0000FF'>typename</font> T, 
        <font color='#0000FF'>typename</font> U
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>double</u></font> <b><a name='find_max_bobyqa'></a>find_max_bobyqa</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> funct<font color='#5555FF'>&amp;</font> f,
        T<font color='#5555FF'>&amp;</font> x,
        <font color='#0000FF'><u>long</u></font> npt,
        <font color='#0000FF'>const</font> U<font color='#5555FF'>&amp;</font> x_lower,
        <font color='#0000FF'>const</font> U<font color='#5555FF'>&amp;</font> x_upper,
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> rho_begin,
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> rho_end,
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> max_f_evals
    <font face='Lucida Console'>)</font> 
    <b>{</b>
        <font color='#009900'>// The starting point (i.e. x) must be a column vector.  
</font>        <font color='#BB00BB'>COMPILE_TIME_ASSERT</font><font face='Lucida Console'>(</font>T::NC <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>return</font> <font color='#5555FF'>-</font><font color='#BB00BB'>find_min_bobyqa</font><font face='Lucida Console'>(</font><font color='#BB00BB'>negate_function</font><font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font>, x, npt, x_lower, x_upper, rho_begin, rho_end, max_f_evals<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<b>}</b>

<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_OPTIMIZATIOn_BOBYQA_Hh_
</font>

</pre></body></html>